shutdown() {
synchronized (AbstractLightyModule.this) {
LOG.debug("Starting shutdown procedure of LightyModule {}.", this.getClass().getSimpleName());
final boolean stopResult = stopProcedure();
- this.shutdownLatch.countDown();
this.running = false;
LOG.info("LightyModule {} shutdown complete.", this.getClass().getSimpleName());
return stopResult;
@@ -207,4 +208,21 @@ public final boolean shutdown(final long duration, final TimeUnit unit) {
}
return false;
}
+
+ /**
+ * Invoke blocking shutdown after blocking start.
+ *
+ *
+ * Release CountDownLatch locking this thread and shutdown.
+ * @param duration duration to wait for shutdown to complete
+ * @param unit {@link TimeUnit} of {@code duration}
+ * @return {@code boolean} indicating shutdown sucess
+ * @deprecated Use {@code shutdown()} or {@code shutdown(duration, unit)} instead in case you want
+ * blocking shutdown.
+ */
+ @Deprecated(forRemoval = true)
+ public final boolean shutdownBlocking(final long duration, final TimeUnit unit) {
+ shutdownLatch.countDown();
+ return shutdown(duration, unit);
+ }
}
diff --git a/lighty-core/lighty-controller/src/main/java/io/lighty/core/controller/api/LightyModule.java b/lighty-core/lighty-controller/src/main/java/io/lighty/core/controller/api/LightyModule.java
index c88b5458e8..add4da7bbf 100644
--- a/lighty-core/lighty-controller/src/main/java/io/lighty/core/controller/api/LightyModule.java
+++ b/lighty-core/lighty-controller/src/main/java/io/lighty/core/controller/api/LightyModule.java
@@ -30,7 +30,9 @@ public interface LightyModule {
* Start and block until shutdown is requested.
*
* @throws InterruptedException thrown in case module initialization fails.
+ * @deprecated Use @{@code start.get()} instead in case you want blocking start.
*/
+ @Deprecated(forRemoval = true)
void startBlocking() throws InterruptedException;
/**
diff --git a/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/api/LightyModuleTest.java b/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/api/LightyModuleTest.java
index dd9c7e85ee..c457489b03 100644
--- a/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/api/LightyModuleTest.java
+++ b/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/api/LightyModuleTest.java
@@ -7,13 +7,9 @@
*/
package io.lighty.core.controller.api;
-import com.google.common.util.concurrent.SettableFuture;
import io.lighty.core.controller.impl.LightyControllerBuilder;
import io.lighty.core.controller.impl.util.ControllerConfigUtils;
-import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@@ -24,9 +20,9 @@
import org.testng.annotations.Test;
public class LightyModuleTest {
- private static long MAX_INIT_TIMEOUT = 15000L;
- private static long MAX_SHUTDOWN_TIMEOUT = 15000L;
- private static long SLEEP_AFTER_SHUTDOWN_TIMEOUT = 800L;
+ private static final long MAX_INIT_TIMEOUT = 15000L;
+ private static final long MAX_SHUTDOWN_TIMEOUT = 15000L;
+
private ExecutorService executorService;
private LightyModule moduleUnderTest;
@@ -55,7 +51,7 @@ public void shutdownExecutor() {
@Test
public void testStartShutdown() throws Exception {
this.moduleUnderTest = getModuleUnderTest(getExecutorService());
- startLightyModuleAndFailIfTimedOut();
+ this.moduleUnderTest.start().get(MAX_INIT_TIMEOUT, TimeUnit.MILLISECONDS);
Mockito.verify(executorService, Mockito.times(1)).execute(Mockito.any());
this.moduleUnderTest.shutdown(MAX_SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS);
Mockito.verify(executorService, Mockito.times(2)).execute(Mockito.any());
@@ -71,10 +67,9 @@ public void testStartStop_whenAlreadyStartedStopped() throws Exception {
Assert.fail("Init timed out.", e);
}
Mockito.verify(executorService, Mockito.times(1)).execute(Mockito.any());
- this.moduleUnderTest.shutdown();
+ this.moduleUnderTest.shutdown(MAX_SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS);
Mockito.verify(executorService, Mockito.times(2)).execute(Mockito.any());
- Thread.sleep(SLEEP_AFTER_SHUTDOWN_TIMEOUT);
- this.moduleUnderTest.shutdown();
+ this.moduleUnderTest.shutdown(MAX_SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS);
Mockito.verify(executorService, Mockito.times(2)).execute(Mockito.any());
}
@@ -82,73 +77,6 @@ public void testStartStop_whenAlreadyStartedStopped() throws Exception {
public void testShutdown_before_start() throws Exception {
this.moduleUnderTest = getModuleUnderTest(getExecutorService());
this.moduleUnderTest.shutdown(MAX_SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS);
-
Mockito.verify(executorService, Mockito.times(0)).execute(Mockito.any());
}
-
- @Test
- public void testStartBlocking_and_shutdown() throws Exception {
- this.moduleUnderTest = getModuleUnderTest(getExecutorService());
- startStopBlocking(this.moduleUnderTest instanceof AbstractLightyModule);
- }
-
- @Test
- public void testStartStopBlocking() throws Exception {
- this.moduleUnderTest = getModuleUnderTest(getExecutorService());
- startStopBlocking(false);
- }
-
- private void startStopBlocking(final boolean isAbstract) throws Exception {
- Future startBlockingFuture;
- if (isAbstract) {
- startBlockingFuture = startBlockingOnLightyModuleAbstractClass();
- } else {
- startBlockingFuture = startBlockingOnLightyModuleInterface();
- }
- //test if thread which invokes startBlocking method is still running (it should be)
- Assert.assertFalse(startBlockingFuture.isDone());
-
- this.moduleUnderTest.shutdown(MAX_SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS);
- try {
- //test if thread which invokes startBlocking method is done after shutdown was called
- //(after small timeout due to synchronization);
- startBlockingFuture.get(SLEEP_AFTER_SHUTDOWN_TIMEOUT, TimeUnit.MILLISECONDS);
- } catch (TimeoutException e) {
- Assert.fail("Waiting for finish of startBlocking method thread timed out. you may consider to adjust"
- + "timeout by overriding SLEEP_AFTER_SHUTDOWN_TIMEOUT", e);
- }
-
- Mockito.verify(executorService, Mockito.times(2)).execute(Mockito.any());
- }
-
- private Future startBlockingOnLightyModuleAbstractClass() throws ExecutionException, InterruptedException {
- SettableFuture initDoneFuture = SettableFuture.create();
- Future startFuture = Executors.newSingleThreadExecutor().submit(() -> {
- ((AbstractLightyModule)this.moduleUnderTest).startBlocking(initDoneFuture::set);
- return true;
- });
- try {
- initDoneFuture.get(MAX_INIT_TIMEOUT, TimeUnit.MILLISECONDS);
- } catch (TimeoutException e) {
- Assert.fail("Init timed out.", e);
- }
- return startFuture;
- }
-
- private Future startBlockingOnLightyModuleInterface() throws InterruptedException {
- Future startFuture = Executors.newSingleThreadExecutor().submit(() -> {
- this.moduleUnderTest.startBlocking();
- return true;
- });
- Thread.sleep(MAX_INIT_TIMEOUT);
- return startFuture;
- }
-
- private void startLightyModuleAndFailIfTimedOut() throws ExecutionException, InterruptedException {
- try {
- this.moduleUnderTest.start().get(MAX_INIT_TIMEOUT, TimeUnit.MILLISECONDS);
- } catch (TimeoutException e) {
- Assert.fail("Init timed out.", e);
- }
- }
}
diff --git a/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/datainit/DataInitTest.java b/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/datainit/DataInitTest.java
index c85c3a5031..1b19ebe952 100644
--- a/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/datainit/DataInitTest.java
+++ b/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/datainit/DataInitTest.java
@@ -25,8 +25,6 @@
import org.testng.annotations.Test;
public class DataInitTest {
- // value from .xml/.json file
- private static int EXPECTED_DARKNESS_FACTOR = 200;
private static final String PATH_TO_JSON_INIT_CONFIG = "/DataInitJsonConfig.json";
private static final String PATH_TO_XML_INIT_CONFIG = "/DataInitXmlConfig.json";
private static final String PATH_TO_INVALID_PATH_TO_INIT_CONFIG = "/DataInitInvalidInitPathConfig.json";
@@ -86,7 +84,6 @@ public void testInvalidInitFilePath() throws Exception {
.build();
boolean result = lightyController.start().get(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
Assert.assertEquals(result,false);
-
}
@Test
@@ -114,10 +111,11 @@ public void shutdownLighty() {
lightyController.shutdown(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
}
- private ToasterListener registerToasterListener(DataBroker dataBroker,
- InstanceIdentifier instanceIdentifier,
- CountDownLatch listenerLatch) {
- ToasterListener listener = new ToasterListener(listenerLatch, EXPECTED_DARKNESS_FACTOR);
+ private ToasterListener registerToasterListener(final DataBroker dataBroker,
+ final InstanceIdentifier instanceIdentifier, final CountDownLatch listenerLatch) {
+ // value from .xml/.json file
+ final int expectedDarknessFactor = 200;
+ ToasterListener listener = new ToasterListener(listenerLatch, expectedDarknessFactor);
dataBroker.registerDataTreeChangeListener(
DataTreeIdentifier.create(LogicalDatastoreType.CONFIGURATION, instanceIdentifier),
listener);
diff --git a/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/impl/tests/LightyControllerMountPointTetst.java b/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/impl/tests/LightyControllerMountPointTest.java
similarity index 97%
rename from lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/impl/tests/LightyControllerMountPointTetst.java
rename to lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/impl/tests/LightyControllerMountPointTest.java
index 7ae4d57a74..f238d05fb8 100644
--- a/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/impl/tests/LightyControllerMountPointTetst.java
+++ b/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/impl/tests/LightyControllerMountPointTest.java
@@ -17,7 +17,7 @@
import org.testng.Assert;
import org.testng.annotations.Test;
-public class LightyControllerMountPointTetst extends LightyControllerTestBase {
+public class LightyControllerMountPointTest extends LightyControllerTestBase {
@Test
public void domMountPointServiceTest() throws Exception {
diff --git a/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/util/FileToDatastoreUtilsTest.java b/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/util/FileToDatastoreUtilsTest.java
index 806c88a6ff..8611d5b56d 100644
--- a/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/util/FileToDatastoreUtilsTest.java
+++ b/lighty-core/lighty-controller/src/test/java/io/lighty/core/controller/util/FileToDatastoreUtilsTest.java
@@ -40,7 +40,6 @@
import org.testng.annotations.Test;
public class FileToDatastoreUtilsTest {
-
private static final String INITIAL_CONTAINER_PATH = "/data/container-value-1.json";
private static final String CASE_CONTAINER_PATH = "/data/case-container-value.json";
private static final String OVERRIDE_CONTAINER_PATH = "/data/container-value-2.xml";
@@ -69,7 +68,7 @@ public class FileToDatastoreUtilsTest {
NodeIdentifier.create(SampleContainer.QNAME),
NodeIdentifier.create(YangModuleInfoImpl.qnameOf("value")));
- private static final long TIMEOUT_MILLIS = 20_000;
+ private static final long TIMEOUT_MILLIS = 60_000;
private LightyController lightyController;
private DataBroker dataBroker;
diff --git a/lighty-core/lighty-minimal-parent/pom.xml b/lighty-core/lighty-minimal-parent/pom.xml
index b4275ced55..ba4085ff16 100644
--- a/lighty-core/lighty-minimal-parent/pom.xml
+++ b/lighty-core/lighty-minimal-parent/pom.xml
@@ -10,7 +10,7 @@
4.0.0
io.lighty.core
lighty-minimal-parent
- 21.0.0
+ 21.1.0-SNAPSHOT
pom
${project.groupId}:${project.artifactId}
@@ -29,14 +29,14 @@
io.lighty.core
dependency-versions
- 21.0.0
+ 21.1.0-SNAPSHOT
pom
import
io.lighty.core
lighty-bom
- 21.0.0
+ 21.1.0-SNAPSHOT
pom
import
@@ -103,7 +103,7 @@
scm:git:https://github.com/PANTHEONtech/lighty.git
scm:git:https://github.com/PANTHEONtech/lighty.git
https://github.com/PANTHEONtech/lighty
- 21.0.0
+ HEAD
diff --git a/lighty-core/lighty-parent/pom.xml b/lighty-core/lighty-parent/pom.xml
index 0fcba67445..6c60deead0 100644
--- a/lighty-core/lighty-parent/pom.xml
+++ b/lighty-core/lighty-parent/pom.xml
@@ -12,7 +12,7 @@
io.lighty.core
lighty-minimal-parent
- 21.0.0
+ 21.1.0-SNAPSHOT
../lighty-minimal-parent
@@ -116,12 +116,12 @@
org.apache.maven.plugins
maven-failsafe-plugin
- 3.5.0
+ 3.5.1
org.apache.maven.plugins
maven-surefire-plugin
- 3.5.0
+ 3.5.1
1
true
@@ -171,7 +171,7 @@
org.apache.maven.plugins
maven-javadoc-plugin
- 3.10.0
+ 3.10.1
true
@@ -203,14 +203,14 @@
org.opendaylight.odlparent
checkstyle
- 14.0.3
+ 14.0.4