Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement detection of redundant launcher execution #89

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions module/communication/controller/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ dependencies {
api(project(":jul.interface"))
api(project(":jul.schedule"))
api(project(":jul.pattern.controller"))
testImplementation("org.testcontainers:junit-jupiter:_") {
exclude(group = "junit", module = "junit")
}
testImplementation("io.quarkus:quarkus-junit4-mock:_") // required as long as testcontainers depends on junit4
testApi(project(":jul.communication.mqtt.test"))
}

description = "JUL Extension Controller"
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.function.Executable;
import org.openbase.jul.communication.iface.RPCServer;
import org.openbase.jul.communication.mqtt.test.MqttIntegrationTest;
import org.openbase.jul.exception.CouldNotPerformException;
import org.openbase.jul.exception.FatalImplementationErrorException;
import org.openbase.jul.exception.InstantiationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.openbase.jul.communication.controller.AbstractControllerServerTest.AbstractControllerServerImpl;
import org.openbase.jul.communication.controller.AbstractControllerServerTest.AbstractRemoteClientImpl;
import org.openbase.jul.communication.iface.RPCServer;
import org.openbase.jul.communication.mqtt.test.MqttIntegrationTest;
import org.openbase.jul.exception.CouldNotPerformException;
import org.openbase.jul.exception.InstantiationException;
import org.openbase.jul.exception.TimeoutException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.openbase.jul.communication.iface.RPCServer;
import org.openbase.jul.communication.mqtt.test.MqttIntegrationTest;
import org.openbase.jul.exception.CouldNotPerformException;
import org.openbase.type.communication.ScopeType.Scope;
import org.openbase.type.domotic.unit.UnitConfigType.UnitConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.openbase.jul.communication.iface.RPCServer;
import org.openbase.jul.communication.mqtt.CommunicatorFactoryImpl;
import org.openbase.jul.communication.mqtt.DefaultCommunicatorConfig;
import org.openbase.jul.communication.mqtt.test.MqttIntegrationTest;
import org.openbase.jul.exception.CouldNotPerformException;
import org.openbase.jul.extension.type.processing.ScopeProcessor;
import org.openbase.jul.iface.Requestable;
Expand Down

This file was deleted.

29 changes: 29 additions & 0 deletions module/communication/mqtttest/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This project uses @Incubating APIs which are subject to change.
*/

plugins {
id("org.openbase.jul")
}

dependencies {
api(project(":jul.communication"))
api(project(":jul.schedule"))
api(project(":jul.extension.type.processing"))
api(project(":jul.communication.mqtt"))
api("com.hivemq:hivemq-mqtt-client:_")
api("org.testcontainers:junit-jupiter:_") {
exclude(group = "junit", module = "junit")
}
api("io.quarkus:quarkus-junit4-mock:_")
api(Testing.junit.jupiter)
api(Testing.junit.jupiter.api)
}

description = "JUL Extension MQTT Test"

java {
withJavadocJar()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package org.openbase.jul.communication.mqtt.test
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.TestInstance
import org.openbase.jps.core.JPService
import org.openbase.jps.exception.JPServiceException
import org.openbase.jul.communication.jp.JPComHost
import org.openbase.jul.communication.jp.JPComPort
import org.openbase.jul.communication.mqtt.SharedMqttClient.waitForShutdown
import org.testcontainers.containers.BindMode
import org.testcontainers.containers.GenericContainer
import org.testcontainers.utility.DockerImageName
import java.nio.file.Files
import java.nio.file.Path
import java.time.Duration
import java.util.*

/*-
* #%L
* JUL Extension Controller
* %%
* Copyright (C) 2015 - 2021 openbase.org
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-3.0.html>.
* #L%

* */
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
open class MqttIntegrationTest {

companion object {
const val port = 1884
var mosquittoConfig: Path? = null
var broker: GenericContainer<*>? = null
val configLock = Any()
}

@BeforeAll
fun setupMqtt() {
synchronized(configLock) {
mosquittoConfig = Files.createTempFile("mosquitto_", ".conf")
Files.write(
mosquittoConfig, listOf(
"allow_anonymous true",
"listener " + port
)
)
GenericContainer(DockerImageName.parse("eclipse-mosquitto"))
.withExposedPorts(port)
.withFileSystemBind(
mosquittoConfig.toString(),
"/mosquitto/config/mosquitto.conf",
BindMode.READ_ONLY
)
.apply { withStartupTimeout(Duration.ofSeconds(30)).start() }
.also { if (broker?.takeIf { it.containerId != null } != null) error("broker was already initialized!") }
Fixed Show fixed Hide fixed
.also { broker = it }
.also { setupProperties() }
}
}

@AfterAll
fun tearDownMQTT() {
synchronized(configLock) {
waitForShutdown()
broker?.stop()
Files.delete(mosquittoConfig)
}
}

@Throws(JPServiceException::class)
private fun setupProperties() {
JPService.reset()
JPService.registerProperty(JPComPort::class.java, broker!!.firstMappedPort)
JPService.registerProperty(JPComHost::class.java, broker!!.host)
setupCustomProperties()
JPService.setupJUnitTestMode()
}

open fun setupCustomProperties() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.openbase.jul.exception.FatalImplementationErrorException;
import org.openbase.jul.exception.MultiException;
import org.openbase.jul.exception.MultiException.SourceExceptionEntry;
import org.openbase.jul.exception.ShutdownException;
import org.slf4j.Logger;

/**
Expand Down Expand Up @@ -214,8 +215,7 @@ public static <T extends Throwable> void printHistory(final String message, T th
public static <T extends Throwable> void printHistoryAndExit(final String message, T th, final Logger logger) {
printHistory(new CouldNotPerformException(message, th), logger, LogLevel.ERROR);
if (JPService.testMode()) {
assert false;
return;
throw new RuntimeException(new ShutdownException(message, th));
}
exit(255);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,17 @@ public void unlockWrite(final NotificationStrategy notificationStrategy) {
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
return;
} catch (NotInitializedException ex) {
// do nothing if service is not initialized yet
} catch (CouldNotPerformException ex) {
// only print error if the exception was not caused by a system shutdown.
if (!ExceptionProcessor.isCausedBySystemShutdown(ex)) {
ExceptionPrinter.printHistory(new CouldNotPerformException("Could not inform builder holder about data update!", ex), logger, LogLevel.ERROR);
ExceptionPrinter.printHistory(
"Could not inform builder holder about data update!",
ex,
logger,
LogLevel.ERROR
);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions module/pattern/launch/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ plugins {
dependencies {
api(project(":jul.interface"))
api(project(":jul.communication.controller"))
testApi(project(":jul.communication.mqtt.test"))
}

description = "JUL Pattern Launch"
Expand Down
Loading