From 0f52b339ddac8ce247fc8c8883aea30e94d8170c Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Fri, 7 Jun 2024 09:26:18 +0200 Subject: [PATCH] [FEAT] use Maven a build system root tool --- .classpath | 26 +- .project | 18 +- pom.xml | 123 ++++++ src/org/atriasoft/esignal/ISignal.java | 2 +- src/org/atriasoft/esignal/ISignalEmpty.java | 2 +- src/org/atriasoft/esignal/Signal.java | 4 +- src/org/atriasoft/esignal/SignalEmpty.java | 4 +- test/src/test/atriasoft/esignal/Log.java | 59 --- .../test/atriasoft/esignal/TestISignal.java | 330 +++++++------- .../atriasoft/esignal/TestISignalEmpty.java | 406 ++++++++--------- .../test/atriasoft/esignal/TestSignal.java | 410 +++++++++--------- .../atriasoft/esignal/TestSignalEmpty.java | 280 ++++++------ 12 files changed, 868 insertions(+), 796 deletions(-) create mode 100644 pom.xml delete mode 100644 test/src/test/atriasoft/esignal/Log.java diff --git a/.classpath b/.classpath index 00e8b90..5cd2633 100644 --- a/.classpath +++ b/.classpath @@ -1,36 +1,28 @@ - + + - + - + - + + - + - + - - - - - - - - - - - + diff --git a/.project b/.project index 9adf61a..211c980 100644 --- a/.project +++ b/.project @@ -1,9 +1,8 @@ - atriasoft-esignal + esignal - atriasoft-esignal @@ -12,24 +11,13 @@ - net.sf.eclipsecs.core.CheckstyleBuilder + org.eclipse.m2e.core.maven2Builder org.eclipse.jdt.core.javanature - net.sf.eclipsecs.core.CheckstyleNature + org.eclipse.m2e.core.maven2Nature - - - 1646149232191 - - 30 - - org.eclipse.core.resources.regexFilterMatcher - node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ - - - diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f02e42c --- /dev/null +++ b/pom.xml @@ -0,0 +1,123 @@ + + 4.0.0 + org.atriasoft + esignal + 0.1.0 + + 3.13.0 + 21 + 21 + 3.1.1 + + + + + gitea + https://gitea.atria-soft.org/api/packages/org.atriasoft/maven + + + + + gitea + https://gitea.atria-soft.org/api/packages/org.atriasoft/maven + + + gitea + https://gitea.atria-soft.org/api/packages/org.atriasoft/maven + + + + + + org.atriasoft + etk + 0.1.0 + + + org.junit.jupiter + junit-jupiter-api + 5.9.3 + test + + + org.slf4j + slf4j-simple + 2.0.7 + test + + + + + src + test/src + ${project.basedir}/out/maven/ + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.compiler.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M5 + + + maven-assembly-plugin + + + + fully.qualified.MainClass + + + + jar-with-dependencies + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.2.0 + + private + true + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.2.0 + + public + + + + + + diff --git a/src/org/atriasoft/esignal/ISignal.java b/src/org/atriasoft/esignal/ISignal.java index 7265813..8384de8 100644 --- a/src/org/atriasoft/esignal/ISignal.java +++ b/src/org/atriasoft/esignal/ISignal.java @@ -19,7 +19,7 @@ import edu.umd.cs.findbugs.annotations.CheckReturnValue; * signalEvent.setCallBackNotification(this::onConnectionChange); * } * public void onConnectionChange(final int currentNumberConnection, final int deltaConnection) { - * Log.info("Number of connection Change : {} dalta={}", currentNumberConnection, deltaConnection); + * LOGGER.info("Number of connection Change : {} dalta={}", currentNumberConnection, deltaConnection); * } * } * } diff --git a/src/org/atriasoft/esignal/ISignalEmpty.java b/src/org/atriasoft/esignal/ISignalEmpty.java index c4d2699..a57d3ef 100644 --- a/src/org/atriasoft/esignal/ISignalEmpty.java +++ b/src/org/atriasoft/esignal/ISignalEmpty.java @@ -18,7 +18,7 @@ import edu.umd.cs.findbugs.annotations.CheckReturnValue; * signalEvent.setCallBackNotification(this::onConnectionChange); * } * public void onConnectionChange(final int currentNumberConnection, final int deltaConnection) { - * Log.info("Number of connection Change : {} delta={}", currentNumberConnection, deltaConnection); + * LOGGER.info("Number of connection Change : {} delta={}", currentNumberConnection, deltaConnection); * } * } * } diff --git a/src/org/atriasoft/esignal/Signal.java b/src/org/atriasoft/esignal/Signal.java index 4b1ee1b..21aa519 100644 --- a/src/org/atriasoft/esignal/Signal.java +++ b/src/org/atriasoft/esignal/Signal.java @@ -18,12 +18,12 @@ import edu.umd.cs.findbugs.annotations.CheckReturnValue; * * class ReceiverSimple { * public void onEvent(String data) { - * Log.error("function receive: {}", data); + * LOGGER.error("function receive: {}", data); * } * public connectLambda(EmiterSimple other) { * // Note : this lambda is reference a a global, then it will never removed in the connection list ==> refer the local class or @see connectAutoRemoveObject * other.signalEvent.connect((data) -> { - * Log.error("lambda receive: {}", data); + * LOGGER.error("lambda receive: {}", data); * }); * } * } diff --git a/src/org/atriasoft/esignal/SignalEmpty.java b/src/org/atriasoft/esignal/SignalEmpty.java index 1e15551..4391673 100644 --- a/src/org/atriasoft/esignal/SignalEmpty.java +++ b/src/org/atriasoft/esignal/SignalEmpty.java @@ -17,12 +17,12 @@ import edu.umd.cs.findbugs.annotations.CheckReturnValue; * * class ReceiverSimple { * public void onEvent() { - * Log.error("function receive event ..."); + * LOGGER.error("function receive event ..."); * } * public connectLambda(EmiterSimple other) { * // Note : this lambda is reference a a global, then it will never removed in the connection list ==> refer the local class or @see connectAutoRemoveObject * other.signalEvent.connect(() -> { - * Log.error("lambda receive event"); + * LOGGER.error("lambda receive event"); * }); * } * } diff --git a/test/src/test/atriasoft/esignal/Log.java b/test/src/test/atriasoft/esignal/Log.java deleted file mode 100644 index 865bf7a..0000000 --- a/test/src/test/atriasoft/esignal/Log.java +++ /dev/null @@ -1,59 +0,0 @@ -package test.atriasoft.esignal; - -import org.atriasoft.reggol.LogLevel; -import org.atriasoft.reggol.Logger; - -public class Log { - private static final String LIB_NAME = "esignal-test"; - private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME); - private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL); - private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR); - private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING); - private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO); - private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG); - private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE); - private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO); - private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT); - - private Log() {} - - public static void print(String data) { - if (PRINT_PRINT) - Logger.print(LIB_NAME_DRAW, data); - } - - public static void critical(String data) { - if (PRINT_CRITICAL) - Logger.critical(LIB_NAME_DRAW, data); - } - - public static void error(String data) { - if (PRINT_ERROR) - Logger.error(LIB_NAME_DRAW, data); - } - - public static void warning(String data) { - if (PRINT_WARNING) - Logger.warning(LIB_NAME_DRAW, data); - } - - public static void info(String data) { - if (PRINT_INFO) - Logger.info(LIB_NAME_DRAW, data); - } - - public static void debug(String data) { - if (PRINT_DEBUG) - Logger.debug(LIB_NAME_DRAW, data); - } - - public static void verbose(String data) { - if (PRINT_VERBOSE) - Logger.verbose(LIB_NAME_DRAW, data); - } - - public static void todo(String data) { - if (PRINT_TODO) - Logger.todo(LIB_NAME_DRAW, data); - } -} diff --git a/test/src/test/atriasoft/esignal/TestISignal.java b/test/src/test/atriasoft/esignal/TestISignal.java index bb63dc0..5ff2a16 100644 --- a/test/src/test/atriasoft/esignal/TestISignal.java +++ b/test/src/test/atriasoft/esignal/TestISignal.java @@ -13,41 +13,48 @@ import java.util.function.Consumer; import org.atriasoft.esignal.Connection; import org.atriasoft.esignal.ISignal; - -import org.junit.Test; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; //import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @TestMethodOrder(OrderAnnotation.class) public class TestISignal { + static final Logger LOGGER = LoggerFactory.getLogger(TestISignal.class); class EmiterSimple { - public ISignal signalEvent = new ISignal(); + public ISignal signalEvent = new ISignal<>(); public int currentNumberConnection = 0; public int deltaConnection = 0; + public EmiterSimple() { this.signalEvent.setCallBackNotification(this::onConnectionChange); } + public void onConnectionChange(final int currentNumberConnection, final int deltaConnection) { - Log.info(">>>>> Number of connection Change : " + currentNumberConnection + " delta=" + deltaConnection); + LOGGER.info(">>>>> Number of connection Change : " + currentNumberConnection + " delta=" + deltaConnection); this.currentNumberConnection = currentNumberConnection; this.deltaConnection = deltaConnection; } + public void sendEvent(final String value) { this.signalEvent.emit(value); } } + static class ReceiverSimple implements AutoCloseable { private String dataReceive = null; - ReceiverSimple() { - } + + ReceiverSimple() {} // record consumer private Consumer tmpConsumer1 = null; private Connection tmpConnect = null; + @Override public void close() { this.tmpConsumer1 = null; @@ -57,42 +64,47 @@ public class TestISignal { } this.dataReceive = null; } + public void disconnectConnection() { this.tmpConnect.close(); } + public boolean isConnected() { return this.tmpConnect.isConnected(); } - - + public void connect1(final EmiterSimple other) { - WeakReference self = new WeakReference(this); + final WeakReference self = new WeakReference<>(this); this.tmpConnect = other.signalEvent.connect(data -> { - self.get().onData(data); - }); + self.get().onData(data); + }); System.gc(); } + public void connect2(final EmiterSimple other) { - // the solo lambda will not depend on the object => the remove must be done manually... + // the solo lambda will not depend on the object => the remove must be done manually... this.tmpConnect = other.signalEvent.connect(data -> { - Log.error("lambda receive: " + data); - }); + LOGGER.error("lambda receive: " + data); + }); System.gc(); } + public void connect3(final EmiterSimple other) { // we reference the local object, then the lambda is alive while the object is alive... - this.tmpConnect =other.signalEvent.connect(data -> { - Log.error("lambda receive: " + data); - this.dataReceive = data; - }); + this.tmpConnect = other.signalEvent.connect(data -> { + LOGGER.error("lambda receive: " + data); + this.dataReceive = data; + }); System.gc(); } + public void connect4(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(data -> { - onData(data); - }); + onData(data); + }); System.gc(); } + public void connect5(final EmiterSimple other) { this.tmpConsumer1 = this::onData; other.signalEvent.connectWeak(this.tmpConsumer1); @@ -105,10 +117,10 @@ public class TestISignal { } public void connect6(final EmiterSimple other) { - // the solo lambda will not depend on the object => the remove must be done manually... + // the solo lambda will not depend on the object => the remove must be done manually... other.signalEvent.connectAutoRemoveObject(this, data -> { - Log.error("lambda receive: " + data); - }); + LOGGER.error("lambda receive: " + data); + }); System.gc(); } @@ -122,10 +134,9 @@ public class TestISignal { } public void onData(final String data) { - Log.error("Retrive data : " + data); - this.dataReceive = data; + LOGGER.error("Retrive data : " + data); + this.dataReceive = data; } - public void connect8(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(this, ReceiverSimple::onDataStatic); @@ -137,14 +148,12 @@ public class TestISignal { System.gc(); } - public static void onDataStatic(final Object local, final String data) { - ReceiverSimple self = (ReceiverSimple)local; - Log.error("Retrive data : " + data); - self.dataReceive = data; + final ReceiverSimple self = (ReceiverSimple) local; + LOGGER.error("Retrive data : " + data); + self.dataReceive = data; } - public void connect10(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(this, ReceiverSimple::onDataStatic2); System.gc(); @@ -156,31 +165,28 @@ public class TestISignal { } public static void onDataStatic2(final ReceiverSimple self, final String data) { - Log.error("Retrive data : " + data); - self.dataReceive = data; + LOGGER.error("Retrive data : " + data); + self.dataReceive = data; } public void connect12(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(this, (final ReceiverSimple self, final String data) -> { - Log.error("Retrive data : " + data); - self.dataReceive = data; + LOGGER.error("Retrive data : " + data); + self.dataReceive = data; }); System.gc(); } public void connect13(final EmiterSimple other) { other.signalEvent.connectAuto(this, (final ReceiverSimple self, final String data) -> { - Log.error("Retrive data : " + data); - self.dataReceive = data; + LOGGER.error("Retrive data : " + data); + self.dataReceive = data; }); System.gc(); } - - - - + public String getDataAndClean() { - String tmp = this.dataReceive; + final String tmp = this.dataReceive; this.dataReceive = null; return tmp; } @@ -190,63 +196,64 @@ public class TestISignal { @Test @Order(1) public void testConnectAndTransmit1() { - Log.warning("Test 1 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 1 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect1(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); Assertions.assertEquals(1, sender.currentNumberConnection); Assertions.assertEquals(1, sender.deltaConnection); - String testData1 = "MUST receive this data..."; + final String testData1 = "MUST receive this data..."; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); receiver = null; Assertions.assertEquals(1, sender.signalEvent.size()); System.gc(); - String testData2 = "MUST NOT receive this data..."; + final String testData2 = "MUST NOT receive this data..."; sender.sendEvent(testData2); Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(0, sender.currentNumberConnection); Assertions.assertEquals(-1, sender.deltaConnection); - Log.warning("Test 1 [ END ]"); + LOGGER.warn("Test 1 [ END ]"); } + @Test @Order(2) public void testConnectAndTransmit2() { - Log.warning("Test 2 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 2 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect2(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); Assertions.assertEquals(1, sender.currentNumberConnection); Assertions.assertEquals(1, sender.deltaConnection); - String testData1 = "MUST receive this data..."; + final String testData1 = "MUST receive this data..."; sender.sendEvent(testData1); // No data stored ... assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // !!!! NO need to close lambda does not capture the THIS receiver = null; System.gc(); - String testData2 = "Solo Lambda MUST receive this data..."; + final String testData2 = "Solo Lambda MUST receive this data..."; sender.sendEvent(testData2); Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(0, sender.currentNumberConnection); Assertions.assertEquals(-1, sender.deltaConnection); - Log.warning("Test 2 [ END ]"); + LOGGER.warn("Test 2 [ END ]"); } @Test @Order(3) public void testConnectAndTransmit3() { - Log.warning("Test 3 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 3 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect3(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); Assertions.assertEquals(1, sender.currentNumberConnection); Assertions.assertEquals(1, sender.deltaConnection); - String testData1 = "MUST receive this data..."; + final String testData1 = "MUST receive this data..."; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -256,62 +263,62 @@ public class TestISignal { receiver.close(); receiver = null; System.gc(); - String testData2 = "MUST NOT receive this data..."; + final String testData2 = "MUST NOT receive this data..."; sender.sendEvent(testData2); Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(0, sender.currentNumberConnection); Assertions.assertEquals(-1, sender.deltaConnection); - Log.warning("Test 3 [ END ]"); + LOGGER.warn("Test 3 [ END ]"); } @Test @Order(4) public void testConnectAndTransmit4() { - Log.warning("Test 4 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 4 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect4(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data..."; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); // Need to close ==> capture Of this receiver.close(); receiver = null; System.gc(); - String testData2 = "MUST NOT receive this data..."; + final String testData2 = "MUST NOT receive this data..."; sender.sendEvent(testData2); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 4 [ END ]"); + LOGGER.warn("Test 4 [ END ]"); } @Test @Order(5) public void testConnectAndTransmit5() { - Log.warning("Test 5 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 5 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect5(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 111"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // remove connection receiver.disconnectConsumer1(sender); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); - String testData2 = "MUST NOT receive this data... 222"; + final String testData2 = "MUST NOT receive this data... 222"; sender.sendEvent(testData2); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect5(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData3 = "MUST receive this data... 333"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData3 = "MUST receive this data... 333"; sender.sendEvent(testData3); Assertions.assertEquals(testData3, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -319,43 +326,44 @@ public class TestISignal { // check auto remove... receiver = null; System.gc(); - String testData4 = "MUST NOT receive this data... 444"; + final String testData4 = "MUST NOT receive this data... 444"; sender.sendEvent(testData4); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 5 [ END ]"); + LOGGER.warn("Test 5 [ END ]"); } + @Test @Order(6) public void testConnectAndTransmit6() { - Log.warning("Test 6 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 6 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect6(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data..."; sender.sendEvent(testData1); //assertEquals(testData1, receiver.getDataAndClean()); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); receiver = null; System.gc(); - String testData2 = "MUST NOT receive this data..."; + final String testData2 = "MUST NOT receive this data..."; sender.sendEvent(testData2); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 6 [ END ]"); + LOGGER.warn("Test 6 [ END ]"); } @Test @Order(7) public void testConnectAndTransmit7() { - Log.warning("Test 7 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 7 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 111"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -364,14 +372,14 @@ public class TestISignal { receiver.disconnect7(sender); Assertions.assertEquals(false, receiver.isConnected()); System.gc(); - String testData2 = "MUST NOT receive this data... 222"; + final String testData2 = "MUST NOT receive this data... 222"; sender.sendEvent(testData2); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData3 = "MUST receive this data... 333"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData3 = "MUST receive this data... 333"; sender.sendEvent(testData3); Assertions.assertEquals(testData3, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -379,15 +387,15 @@ public class TestISignal { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); - String testData4 = "MUST NOT receive this data... 444"; + final String testData4 = "MUST NOT receive this data... 444"; sender.sendEvent(testData4); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData5 = "MUST receive this data... 555"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData5 = "MUST receive this data... 555"; sender.sendEvent(testData5); Assertions.assertEquals(testData5, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -396,23 +404,23 @@ public class TestISignal { // check auto remove... receiver = null; System.gc(); - String testData6 = "MUST NOT receive this data... 666"; + final String testData6 = "MUST NOT receive this data... 666"; sender.sendEvent(testData6); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 7 [ END ]"); + LOGGER.warn("Test 7 [ END ]"); } @Test @Order(8) public void testConnectAndTransmit8() { - Log.warning("Test 8 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 8 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect8(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 111"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -421,14 +429,14 @@ public class TestISignal { receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); System.gc(); - String testData2 = "MUST NOT receive this data... 222"; + final String testData2 = "MUST NOT receive this data... 222"; sender.sendEvent(testData2); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect8(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData3 = "MUST receive this data... 333"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData3 = "MUST receive this data... 333"; sender.sendEvent(testData3); Assertions.assertEquals(testData3, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -436,61 +444,61 @@ public class TestISignal { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); - String testData4 = "MUST NOT receive this data... 444"; + final String testData4 = "MUST NOT receive this data... 444"; sender.sendEvent(testData4); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect8(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData5 = "MUST receive this data... 555"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData5 = "MUST receive this data... 555"; sender.sendEvent(testData5); Assertions.assertEquals(testData5, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // check auto remove... receiver = null; System.gc(); - String testData6 = "MUST NOT receive this data... 666"; + final String testData6 = "MUST NOT receive this data... 666"; sender.sendEvent(testData6); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 8 [ END ]"); + LOGGER.warn("Test 8 [ END ]"); } @Test @Order(9) public void testConnectAndTransmit9() { - Log.warning("Test 9 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 9 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect9(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 111"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // remove connection (check auto remove)... receiver = null; System.gc(); - String testData6 = "MUST NOT receive this data... 666"; + final String testData6 = "MUST NOT receive this data... 666"; sender.sendEvent(testData6); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 9 [ END ]"); + LOGGER.warn("Test 9 [ END ]"); } @Test @Order(10) public void testConnectAndTransmit10() { - Log.warning("Test 10 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 10 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect10(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 111"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -499,14 +507,14 @@ public class TestISignal { receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); System.gc(); - String testData2 = "MUST NOT receive this data... 222"; + final String testData2 = "MUST NOT receive this data... 222"; sender.sendEvent(testData2); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect10(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData3 = "MUST receive this data... 333"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData3 = "MUST receive this data... 333"; sender.sendEvent(testData3); Assertions.assertEquals(testData3, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -514,61 +522,61 @@ public class TestISignal { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); - String testData4 = "MUST NOT receive this data... 444"; + final String testData4 = "MUST NOT receive this data... 444"; sender.sendEvent(testData4); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect10(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData5 = "MUST receive this data... 555"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData5 = "MUST receive this data... 555"; sender.sendEvent(testData5); Assertions.assertEquals(testData5, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // check auto remove... receiver = null; System.gc(); - String testData6 = "MUST NOT receive this data... 666"; + final String testData6 = "MUST NOT receive this data... 666"; sender.sendEvent(testData6); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 10 [ END ]"); + LOGGER.warn("Test 10 [ END ]"); } @Test @Order(11) public void testConnectAndTransmit11() { - Log.warning("Test 11 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 11 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect11(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 111"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // remove connection (check auto remove)... receiver = null; System.gc(); - String testData6 = "MUST NOT receive this data... 666"; + final String testData6 = "MUST NOT receive this data... 666"; sender.sendEvent(testData6); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 11 [ END ]"); + LOGGER.warn("Test 11 [ END ]"); } @Test @Order(12) public void testConnectAndTransmit12() { - Log.warning("Test 12 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 12 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect12(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 111"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -577,14 +585,14 @@ public class TestISignal { receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); System.gc(); - String testData2 = "MUST NOT receive this data... 222"; + final String testData2 = "MUST NOT receive this data... 222"; sender.sendEvent(testData2); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect12(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData3 = "MUST receive this data... 333"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData3 = "MUST receive this data... 333"; sender.sendEvent(testData3); Assertions.assertEquals(testData3, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -592,58 +600,58 @@ public class TestISignal { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); - String testData4 = "MUST NOT receive this data... 444"; + final String testData4 = "MUST NOT receive this data... 444"; sender.sendEvent(testData4); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect12(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData5 = "MUST receive this data... 555"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData5 = "MUST receive this data... 555"; sender.sendEvent(testData5); Assertions.assertEquals(testData5, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // check auto remove... receiver = null; System.gc(); - String testData6 = "MUST NOT receive this data... 666"; + final String testData6 = "MUST NOT receive this data... 666"; sender.sendEvent(testData6); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 12 [ END ]"); + LOGGER.warn("Test 12 [ END ]"); } @Test @Order(13) public void testConnectAndTransmit13() { - Log.warning("Test 13 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 13 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect13(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 131"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 131"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // remove connection (check auto remove)... receiver = null; System.gc(); - String testData6 = "MUST NOT receive this data... 666"; + final String testData6 = "MUST NOT receive this data... 666"; sender.sendEvent(testData6); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 13 [ END ]"); + LOGGER.warn("Test 13 [ END ]"); } @Test public void testClearConnection() { - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); + final EmiterSimple sender = new EmiterSimple(); + final ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.signalEvent.clear(); } } diff --git a/test/src/test/atriasoft/esignal/TestISignalEmpty.java b/test/src/test/atriasoft/esignal/TestISignalEmpty.java index 9c9d892..0bc5745 100644 --- a/test/src/test/atriasoft/esignal/TestISignalEmpty.java +++ b/test/src/test/atriasoft/esignal/TestISignalEmpty.java @@ -12,41 +12,48 @@ import java.lang.ref.WeakReference; import org.atriasoft.esignal.Connection; import org.atriasoft.esignal.ISignalEmpty; - -import org.junit.Test; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; //import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @TestMethodOrder(OrderAnnotation.class) public class TestISignalEmpty { - + static final Logger LOGGER = LoggerFactory.getLogger(TestISignalEmpty.class); + class EmiterSimple { public ISignalEmpty signalEvent = new ISignalEmpty(); public int currentNumberConnection = 0; public int deltaConnection = 0; + public EmiterSimple() { this.signalEvent.setCallBackNotification(this::onConnectionChange); } + public void onConnectionChange(final int currentNumberConnection, final int deltaConnection) { - Log.info(">>>>> Number of connection Change : " + currentNumberConnection + " delta=" + deltaConnection); + LOGGER.info(">>>>> Number of connection Change : " + currentNumberConnection + " delta=" + deltaConnection); this.currentNumberConnection = currentNumberConnection; this.deltaConnection = deltaConnection; } + public void sendEvent() { this.signalEvent.emit(); } } + static class ReceiverSimple implements AutoCloseable { private boolean dataReceive = false; - ReceiverSimple() { - } - + + ReceiverSimple() {} + // record consumer private Runnable tmpConsumer1 = null; private Connection tmpConnect = null; + @Override public void close() { this.tmpConsumer1 = null; @@ -56,164 +63,164 @@ public class TestISignalEmpty { } this.dataReceive = false; } + public void disconnectConnection() { this.tmpConnect.close(); } + public boolean isConnected() { return this.tmpConnect.isConnected(); } - public void connect1(final EmiterSimple other) { - WeakReference self = new WeakReference(this); + final WeakReference self = new WeakReference<>(this); this.tmpConnect = other.signalEvent.connect(() -> { - self.get().onData(); - }); + self.get().onData(); + }); System.gc(); } + public void connect2(final EmiterSimple other) { - // the solo lambda will not depend on the object => the remove must be done manually... + // the solo lambda will not depend on the object => the remove must be done manually... this.tmpConnect = other.signalEvent.connect(() -> { - Log.error("lambda receive: "); - }); + LOGGER.error("lambda receive: "); + }); System.gc(); } + public void connect3(final EmiterSimple other) { // we reference the local object, then the lambda is alive while the object is alive... - this.tmpConnect =other.signalEvent.connect(() -> { - Log.error("lambda receive: "); - this.dataReceive = true; - }); + this.tmpConnect = other.signalEvent.connect(() -> { + LOGGER.error("lambda receive: "); + this.dataReceive = true; + }); System.gc(); } + public void connect4(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(() -> { - onData(); - }); + onData(); + }); System.gc(); } + public void connect5(final EmiterSimple other) { this.tmpConsumer1 = this::onData; other.signalEvent.connectWeak(this.tmpConsumer1); System.gc(); } - + public void disconnectConsumer1(final EmiterSimple other) { other.signalEvent.disconnect(this.tmpConsumer1); this.tmpConsumer1 = null; } - + public void connect6(final EmiterSimple other) { - // the solo lambda will not depend on the object => the remove must be done manually... + // the solo lambda will not depend on the object => the remove must be done manually... other.signalEvent.connectAutoRemoveObject(this, () -> { - Log.error("lambda receive: "); - }); + LOGGER.error("lambda receive: "); + }); System.gc(); } - + public void connect7(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(this::onData); System.gc(); } - + public void disconnect7(final EmiterSimple other) { other.signalEvent.disconnect(this.tmpConnect); } - + public void onData() { - Log.error("Retrive data : "); - this.dataReceive = true; + LOGGER.error("Retrive data : "); + this.dataReceive = true; } - public void connect8(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(this, ReceiverSimple::onDataStatic); System.gc(); } - + public void connect9(final EmiterSimple other) { other.signalEvent.connectAuto(this, ReceiverSimple::onDataStatic); System.gc(); } - - + public static void onDataStatic(final Object local) { - ReceiverSimple self = (ReceiverSimple)local; - Log.error("Retrive data : "); - self.dataReceive = true; + final ReceiverSimple self = (ReceiverSimple) local; + LOGGER.error("Retrive data : "); + self.dataReceive = true; } - - + public void connect10(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(this, ReceiverSimple::onDataStatic2); System.gc(); } - + public void connect11(final EmiterSimple other) { other.signalEvent.connectAuto(this, ReceiverSimple::onDataStatic2); System.gc(); } - + public static void onDataStatic2(final ReceiverSimple self) { - Log.error("Retrive data : "); - self.dataReceive = true; - } - - public void connect12(final EmiterSimple other) { - this.tmpConnect = other.signalEvent.connect(this, (final ReceiverSimple self) -> { - Log.error("Retrive data : "); - self.dataReceive = true; - }); - System.gc(); + LOGGER.error("Retrive data : "); + self.dataReceive = true; } - public void connect13(final EmiterSimple other) { - other.signalEvent.connectAuto(this, (final ReceiverSimple self) -> { - Log.error("Retrive data : "); - self.dataReceive = true; + public void connect12(final EmiterSimple other) { + this.tmpConnect = other.signalEvent.connect(this, (final ReceiverSimple self) -> { + LOGGER.error("Retrive data : "); + self.dataReceive = true; }); System.gc(); } - - + public void connect13(final EmiterSimple other) { + other.signalEvent.connectAuto(this, (final ReceiverSimple self) -> { + LOGGER.error("Retrive data : "); + self.dataReceive = true; + }); + System.gc(); + } public boolean getDataAndClean() { - boolean tmp = this.dataReceive; + final boolean tmp = this.dataReceive; this.dataReceive = false; return tmp; } - - } + } + @Test @Order(1) public void testConnectAndTransmit1() { - Log.warning("Test 1 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 1 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect1(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); receiver = null; Assertions.assertEquals(1, sender.signalEvent.size()); System.gc(); - + sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 1 [ END ]"); - + LOGGER.warn("Test 1 [ END ]"); + } + @Test @Order(2) public void testConnectAndTransmit2() { - Log.warning("Test 2 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 2 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect2(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); // No data stored ... assertEquals(true, receiver.getDataAndClean()); @@ -221,23 +228,23 @@ public class TestISignalEmpty { // !!!! NO need to close lambda does not capture the THIS receiver = null; System.gc(); - + sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 2 [ END ]"); + LOGGER.warn("Test 2 [ END ]"); } - + @Test @Order(3) public void testConnectAndTransmit3() { - Log.warning("Test 3 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 3 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect3(sender); Assertions.assertEquals(1, sender.signalEvent.size()); Assertions.assertEquals(1, sender.currentNumberConnection); Assertions.assertEquals(1, sender.deltaConnection); - + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -245,67 +252,67 @@ public class TestISignalEmpty { receiver.close(); receiver = null; System.gc(); - + Assertions.assertEquals(0, sender.currentNumberConnection); Assertions.assertEquals(-1, sender.deltaConnection); sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 3 [ END ]"); - - } + LOGGER.warn("Test 3 [ END ]"); + } + @Test @Order(4) public void testConnectAndTransmit4() { - Log.warning("Test 4 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 4 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect4(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); Assertions.assertEquals(1, sender.currentNumberConnection); Assertions.assertEquals(1, sender.deltaConnection); - + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); // Need to close ==> capture Of this receiver.close(); receiver = null; System.gc(); - + Assertions.assertEquals(0, sender.currentNumberConnection); Assertions.assertEquals(-1, sender.deltaConnection); sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 4 [ END ]"); - - } + LOGGER.warn("Test 4 [ END ]"); + } + @Test @Order(5) public void testConnectAndTransmit5() { - Log.warning("Test 5 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 5 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect5(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); Assertions.assertEquals(1, sender.currentNumberConnection); Assertions.assertEquals(1, sender.deltaConnection); - + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // remove connection receiver.disconnectConsumer1(sender); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); - + sender.sendEvent(); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect5(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -314,46 +321,47 @@ public class TestISignalEmpty { // check auto remove... receiver = null; System.gc(); - + Assertions.assertEquals(1, sender.currentNumberConnection); Assertions.assertEquals(1, sender.deltaConnection); sender.sendEvent(); Assertions.assertEquals(0, sender.currentNumberConnection); Assertions.assertEquals(-1, sender.deltaConnection); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 5 [ END ]"); - + LOGGER.warn("Test 5 [ END ]"); + } + @Test @Order(6) public void testConnectAndTransmit6() { - Log.warning("Test 6 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 6 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect6(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); //assertEquals(true, receiver.getDataAndClean()); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); receiver = null; System.gc(); - + sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 6 [ END ]"); - - } + LOGGER.warn("Test 6 [ END ]"); + } + @Test @Order(7) public void testConnectAndTransmit7() { - Log.warning("Test 7 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 7 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -363,13 +371,13 @@ public class TestISignalEmpty { receiver.disconnect7(sender); Assertions.assertEquals(false, receiver.isConnected()); System.gc(); - + sender.sendEvent(); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -378,14 +386,14 @@ public class TestISignalEmpty { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); - + sender.sendEvent(); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -395,22 +403,22 @@ public class TestISignalEmpty { // check auto remove... receiver = null; System.gc(); - + sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 7 [ END ]"); - - } + LOGGER.warn("Test 7 [ END ]"); + } + @Test @Order(8) public void testConnectAndTransmit8() { - Log.warning("Test 8 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 8 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect8(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -420,13 +428,13 @@ public class TestISignalEmpty { receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); System.gc(); - + sender.sendEvent(); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect8(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -435,14 +443,14 @@ public class TestISignalEmpty { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); - + sender.sendEvent(); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect8(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -450,22 +458,22 @@ public class TestISignalEmpty { // check auto remove... receiver = null; System.gc(); - + sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 8 [ END ]"); - + LOGGER.warn("Test 8 [ END ]"); + } - + @Test @Order(9) public void testConnectAndTransmit9() { - Log.warning("Test 9 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 9 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect9(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -473,22 +481,22 @@ public class TestISignalEmpty { // remove connection (check auto remove)... receiver = null; System.gc(); - + sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 9 [ END ]"); - - } + LOGGER.warn("Test 9 [ END ]"); + } + @Test @Order(10) public void testConnectAndTransmit10() { - Log.warning("Test 10 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 10 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect10(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -498,13 +506,13 @@ public class TestISignalEmpty { receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); System.gc(); - + sender.sendEvent(); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect10(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -513,14 +521,14 @@ public class TestISignalEmpty { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); - + sender.sendEvent(); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect10(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -528,22 +536,22 @@ public class TestISignalEmpty { // check auto remove... receiver = null; System.gc(); - + sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 10 [ END ]"); - + LOGGER.warn("Test 10 [ END ]"); + } - + @Test @Order(11) public void testConnectAndTransmit11() { - Log.warning("Test 11 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 11 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect11(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -551,22 +559,22 @@ public class TestISignalEmpty { // remove connection (check auto remove)... receiver = null; System.gc(); - + sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 11 [ END ]"); - - } + LOGGER.warn("Test 11 [ END ]"); + } + @Test @Order(12) public void testConnectAndTransmit12() { - Log.warning("Test 12 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 12 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect12(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -576,13 +584,13 @@ public class TestISignalEmpty { receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); System.gc(); - + sender.sendEvent(); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect12(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -591,14 +599,14 @@ public class TestISignalEmpty { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); - + sender.sendEvent(); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect12(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -606,22 +614,22 @@ public class TestISignalEmpty { // check auto remove... receiver = null; System.gc(); - + sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 12 [ END ]"); - + LOGGER.warn("Test 12 [ END ]"); + } - + @Test @Order(13) public void testConnectAndTransmit13() { - Log.warning("Test 13 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 13 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect13(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); @@ -629,55 +637,55 @@ public class TestISignalEmpty { // remove connection (check auto remove)... receiver = null; System.gc(); - + sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 13 [ END ]"); - } - - @Test - public void testEmptyConnection() { - Log.warning("Test 8 [BEGIN]"); - Connection con = new Connection(); - Assertions.assertEquals(false, con.isConnected()); - con.close(); - Log.warning("Test 8 [ END ]"); + LOGGER.warn("Test 13 [ END ]"); } + @Test + public void testEmptyConnection() { + LOGGER.warn("Test 8 [BEGIN]"); + final Connection con = new Connection(); + Assertions.assertEquals(false, con.isConnected()); + con.close(); + LOGGER.warn("Test 8 [ END ]"); + } + @Test public void testClearConnection() { - Log.warning("Test 9 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); + LOGGER.warn("Test 9 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); + final ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect7(sender); Assertions.assertEquals(1, sender.currentNumberConnection); Assertions.assertEquals(1, sender.deltaConnection); receiver.connect5(sender); - + Assertions.assertEquals(2, sender.currentNumberConnection); Assertions.assertEquals(1, sender.deltaConnection); - - Assertions.assertEquals(2, sender.signalEvent.size()); - sender.signalEvent.clear(); + Assertions.assertEquals(2, sender.signalEvent.size()); + sender.signalEvent.clear(); + Assertions.assertEquals(0, sender.currentNumberConnection); Assertions.assertEquals(-2, sender.deltaConnection); - Log.warning("Test 9 [ END ]"); + LOGGER.warn("Test 9 [ END ]"); } - + @Test public void testDisconnectionRemovedSignal() { - Log.warning("Test 10 [BEGIN]"); + LOGGER.warn("Test 10 [BEGIN]"); EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); + final ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender = null; System.gc(); Assertions.assertEquals(false, receiver.isConnected()); receiver.close(); - Log.warning("Test 10 [ END ]"); + LOGGER.warn("Test 10 [ END ]"); } } diff --git a/test/src/test/atriasoft/esignal/TestSignal.java b/test/src/test/atriasoft/esignal/TestSignal.java index c65911e..62341e6 100644 --- a/test/src/test/atriasoft/esignal/TestSignal.java +++ b/test/src/test/atriasoft/esignal/TestSignal.java @@ -13,31 +13,36 @@ import java.util.function.Consumer; import org.atriasoft.esignal.Connection; import org.atriasoft.esignal.Signal; - -import org.junit.Test; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; //import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @TestMethodOrder(OrderAnnotation.class) public class TestSignal { - + static final Logger LOGGER = LoggerFactory.getLogger(TestSignal.class); + class EmiterSimple { - public Signal signalEvent = new Signal(); + public Signal signalEvent = new Signal<>(); + public void sendEvent(final String value) { this.signalEvent.emit(value); } } + static class ReceiverSimple implements AutoCloseable { private String dataReceive = null; - ReceiverSimple() { - } - + + ReceiverSimple() {} + // record consumer private Consumer tmpConsumer1 = null; private Connection tmpConnect = null; + @Override public void close() { this.tmpConsumer1 = null; @@ -47,186 +52,186 @@ public class TestSignal { } this.dataReceive = null; } + public void disconnectConnection() { this.tmpConnect.close(); } + public boolean isConnected() { return this.tmpConnect.isConnected(); } - public void connect1(final EmiterSimple other) { - WeakReference self = new WeakReference(this); + final WeakReference self = new WeakReference<>(this); this.tmpConnect = other.signalEvent.connect(data -> { - self.get().onData(data); - }); + self.get().onData(data); + }); System.gc(); } + public void connect2(final EmiterSimple other) { - // the solo lambda will not depend on the object => the remove must be done manually... + // the solo lambda will not depend on the object => the remove must be done manually... this.tmpConnect = other.signalEvent.connect(data -> { - Log.error("lambda receive: " + data); - }); + LOGGER.error("lambda receive: " + data); + }); System.gc(); } + public void connect3(final EmiterSimple other) { // we reference the local object, then the lambda is alive while the object is alive... - this.tmpConnect =other.signalEvent.connect(data -> { - Log.error("lambda receive: " + data); - this.dataReceive = data; - }); + this.tmpConnect = other.signalEvent.connect(data -> { + LOGGER.error("lambda receive: " + data); + this.dataReceive = data; + }); System.gc(); } + public void connect4(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(data -> { - onData(data); - }); + onData(data); + }); System.gc(); } + public void connect5(final EmiterSimple other) { this.tmpConsumer1 = this::onData; other.signalEvent.connectWeak(this.tmpConsumer1); System.gc(); } - + public void disconnectConsumer1(final EmiterSimple other) { other.signalEvent.disconnect(this.tmpConsumer1); this.tmpConsumer1 = null; } - + public void connect6(final EmiterSimple other) { - // the solo lambda will not depend on the object => the remove must be done manually... + // the solo lambda will not depend on the object => the remove must be done manually... other.signalEvent.connectAutoRemoveObject(this, data -> { - Log.error("lambda receive: " + data); - }); + LOGGER.error("lambda receive: " + data); + }); System.gc(); } - + public void connect7(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(this::onData); System.gc(); } - + public void disconnect7(final EmiterSimple other) { other.signalEvent.disconnect(this.tmpConnect); } - + public void onData(final String data) { - Log.error("Retrive data : " + data); - this.dataReceive = data; + LOGGER.error("Retrive data : " + data); + this.dataReceive = data; } - public void connect8(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(this, ReceiverSimple::onDataStatic); System.gc(); } - + public void connect9(final EmiterSimple other) { other.signalEvent.connectAuto(this, ReceiverSimple::onDataStatic); System.gc(); } - - + public static void onDataStatic(final Object local, final String data) { - ReceiverSimple self = (ReceiverSimple)local; - Log.error("Retrive data : " + data); - self.dataReceive = data; + final ReceiverSimple self = (ReceiverSimple) local; + LOGGER.error("Retrive data : " + data); + self.dataReceive = data; } - - + public void connect10(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(this, ReceiverSimple::onDataStatic2); System.gc(); } - + public void connect11(final EmiterSimple other) { other.signalEvent.connectAuto(this, ReceiverSimple::onDataStatic2); System.gc(); } - + public static void onDataStatic2(final ReceiverSimple self, final String data) { - Log.error("Retrive data : " + data); - self.dataReceive = data; - } - - public void connect12(final EmiterSimple other) { - this.tmpConnect = other.signalEvent.connect(this, (final ReceiverSimple self, final String data) -> { - Log.error("Retrive data : " + data); - self.dataReceive = data; - }); - System.gc(); + LOGGER.error("Retrive data : " + data); + self.dataReceive = data; } - public void connect13(final EmiterSimple other) { - other.signalEvent.connectAuto(this, (final ReceiverSimple self, final String data) -> { - Log.error("Retrive data : " + data); - self.dataReceive = data; + public void connect12(final EmiterSimple other) { + this.tmpConnect = other.signalEvent.connect(this, (final ReceiverSimple self, final String data) -> { + LOGGER.error("Retrive data : " + data); + self.dataReceive = data; }); System.gc(); } - - + public void connect13(final EmiterSimple other) { + other.signalEvent.connectAuto(this, (final ReceiverSimple self, final String data) -> { + LOGGER.error("Retrive data : " + data); + self.dataReceive = data; + }); + System.gc(); + } public String getDataAndClean() { - String tmp = this.dataReceive; + final String tmp = this.dataReceive; this.dataReceive = null; return tmp; } - - } + } + @Test @Order(1) public void testConnectAndTransmit1() { - Log.warning("Test 1 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 1 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect1(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data..."; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); receiver = null; Assertions.assertEquals(1, sender.signalEvent.size()); System.gc(); - String testData2 = "MUST NOT receive this data..."; + final String testData2 = "MUST NOT receive this data..."; sender.sendEvent(testData2); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 1 [ END ]"); - + LOGGER.warn("Test 1 [ END ]"); + } + @Test @Order(2) public void testConnectAndTransmit2() { - Log.warning("Test 2 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 2 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect2(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data..."; sender.sendEvent(testData1); // No data stored ... assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // !!!! NO need to close lambda does not capture the THIS receiver = null; System.gc(); - String testData2 = "Solo Lambda MUST receive this data..."; + final String testData2 = "Solo Lambda MUST receive this data..."; sender.sendEvent(testData2); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 2 [ END ]"); + LOGGER.warn("Test 2 [ END ]"); } - + @Test @Order(3) public void testConnectAndTransmit3() { - Log.warning("Test 3 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 3 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect3(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data..."; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -234,60 +239,60 @@ public class TestSignal { receiver.close(); receiver = null; System.gc(); - String testData2 = "MUST NOT receive this data..."; + final String testData2 = "MUST NOT receive this data..."; sender.sendEvent(testData2); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 3 [ END ]"); - - } + LOGGER.warn("Test 3 [ END ]"); + } + @Test @Order(4) public void testConnectAndTransmit4() { - Log.warning("Test 4 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 4 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect4(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data..."; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); // Need to close ==> capture Of this receiver.close(); receiver = null; System.gc(); - String testData2 = "MUST NOT receive this data..."; + final String testData2 = "MUST NOT receive this data..."; sender.sendEvent(testData2); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 4 [ END ]"); - - } + LOGGER.warn("Test 4 [ END ]"); + } + @Test @Order(5) public void testConnectAndTransmit5() { - Log.warning("Test 5 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 5 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect5(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 111"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // remove connection receiver.disconnectConsumer1(sender); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); - String testData2 = "MUST NOT receive this data... 222"; + final String testData2 = "MUST NOT receive this data... 222"; sender.sendEvent(testData2); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect5(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData3 = "MUST receive this data... 333"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData3 = "MUST receive this data... 333"; sender.sendEvent(testData3); Assertions.assertEquals(testData3, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -295,43 +300,44 @@ public class TestSignal { // check auto remove... receiver = null; System.gc(); - String testData4 = "MUST NOT receive this data... 444"; + final String testData4 = "MUST NOT receive this data... 444"; sender.sendEvent(testData4); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 5 [ END ]"); - + LOGGER.warn("Test 5 [ END ]"); + } + @Test @Order(6) public void testConnectAndTransmit6() { - Log.warning("Test 6 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 6 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect6(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data..."; sender.sendEvent(testData1); //assertEquals(testData1, receiver.getDataAndClean()); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); receiver = null; System.gc(); - String testData2 = "MUST NOT receive this data..."; + final String testData2 = "MUST NOT receive this data..."; sender.sendEvent(testData2); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 6 [ END ]"); - - } + LOGGER.warn("Test 6 [ END ]"); + } + @Test @Order(7) public void testConnectAndTransmit7() { - Log.warning("Test 7 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 7 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 111"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -340,14 +346,14 @@ public class TestSignal { receiver.disconnect7(sender); Assertions.assertEquals(false, receiver.isConnected()); System.gc(); - String testData2 = "MUST NOT receive this data... 222"; + final String testData2 = "MUST NOT receive this data... 222"; sender.sendEvent(testData2); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData3 = "MUST receive this data... 333"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData3 = "MUST receive this data... 333"; sender.sendEvent(testData3); Assertions.assertEquals(testData3, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -355,15 +361,15 @@ public class TestSignal { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); - String testData4 = "MUST NOT receive this data... 444"; + final String testData4 = "MUST NOT receive this data... 444"; sender.sendEvent(testData4); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData5 = "MUST receive this data... 555"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData5 = "MUST receive this data... 555"; sender.sendEvent(testData5); Assertions.assertEquals(testData5, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -372,23 +378,23 @@ public class TestSignal { // check auto remove... receiver = null; System.gc(); - String testData6 = "MUST NOT receive this data... 666"; + final String testData6 = "MUST NOT receive this data... 666"; sender.sendEvent(testData6); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 7 [ END ]"); - - } + LOGGER.warn("Test 7 [ END ]"); + } + @Test @Order(8) public void testConnectAndTransmit8() { - Log.warning("Test 8 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 8 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect8(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 111"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -397,14 +403,14 @@ public class TestSignal { receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); System.gc(); - String testData2 = "MUST NOT receive this data... 222"; + final String testData2 = "MUST NOT receive this data... 222"; sender.sendEvent(testData2); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect8(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData3 = "MUST receive this data... 333"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData3 = "MUST receive this data... 333"; sender.sendEvent(testData3); Assertions.assertEquals(testData3, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -412,61 +418,61 @@ public class TestSignal { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); - String testData4 = "MUST NOT receive this data... 444"; + final String testData4 = "MUST NOT receive this data... 444"; sender.sendEvent(testData4); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect8(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData5 = "MUST receive this data... 555"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData5 = "MUST receive this data... 555"; sender.sendEvent(testData5); Assertions.assertEquals(testData5, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // check auto remove... receiver = null; System.gc(); - String testData6 = "MUST NOT receive this data... 666"; + final String testData6 = "MUST NOT receive this data... 666"; sender.sendEvent(testData6); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 8 [ END ]"); - + LOGGER.warn("Test 8 [ END ]"); + } - + @Test @Order(9) public void testConnectAndTransmit9() { - Log.warning("Test 9 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 9 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect9(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 111"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // remove connection (check auto remove)... receiver = null; System.gc(); - String testData6 = "MUST NOT receive this data... 666"; + final String testData6 = "MUST NOT receive this data... 666"; sender.sendEvent(testData6); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 9 [ END ]"); - - } + LOGGER.warn("Test 9 [ END ]"); + } + @Test @Order(10) public void testConnectAndTransmit10() { - Log.warning("Test 10 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 10 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect10(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 111"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -475,14 +481,14 @@ public class TestSignal { receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); System.gc(); - String testData2 = "MUST NOT receive this data... 222"; + final String testData2 = "MUST NOT receive this data... 222"; sender.sendEvent(testData2); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect10(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData3 = "MUST receive this data... 333"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData3 = "MUST receive this data... 333"; sender.sendEvent(testData3); Assertions.assertEquals(testData3, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -490,61 +496,61 @@ public class TestSignal { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); - String testData4 = "MUST NOT receive this data... 444"; + final String testData4 = "MUST NOT receive this data... 444"; sender.sendEvent(testData4); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect10(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData5 = "MUST receive this data... 555"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData5 = "MUST receive this data... 555"; sender.sendEvent(testData5); Assertions.assertEquals(testData5, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // check auto remove... receiver = null; System.gc(); - String testData6 = "MUST NOT receive this data... 666"; + final String testData6 = "MUST NOT receive this data... 666"; sender.sendEvent(testData6); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 10 [ END ]"); - + LOGGER.warn("Test 10 [ END ]"); + } - + @Test @Order(11) public void testConnectAndTransmit11() { - Log.warning("Test 11 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 11 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect11(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 111"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // remove connection (check auto remove)... receiver = null; System.gc(); - String testData6 = "MUST NOT receive this data... 666"; + final String testData6 = "MUST NOT receive this data... 666"; sender.sendEvent(testData6); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 11 [ END ]"); - - } + LOGGER.warn("Test 11 [ END ]"); + } + @Test @Order(12) public void testConnectAndTransmit12() { - Log.warning("Test 12 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 12 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect12(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 111"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -553,14 +559,14 @@ public class TestSignal { receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); System.gc(); - String testData2 = "MUST NOT receive this data... 222"; + final String testData2 = "MUST NOT receive this data... 222"; sender.sendEvent(testData2); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect12(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData3 = "MUST receive this data... 333"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData3 = "MUST receive this data... 333"; sender.sendEvent(testData3); Assertions.assertEquals(testData3, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -568,58 +574,58 @@ public class TestSignal { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); - String testData4 = "MUST NOT receive this data... 444"; + final String testData4 = "MUST NOT receive this data... 444"; sender.sendEvent(testData4); Assertions.assertEquals(null, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect12(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData5 = "MUST receive this data... 555"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData5 = "MUST receive this data... 555"; sender.sendEvent(testData5); Assertions.assertEquals(testData5, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // check auto remove... receiver = null; System.gc(); - String testData6 = "MUST NOT receive this data... 666"; + final String testData6 = "MUST NOT receive this data... 666"; sender.sendEvent(testData6); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 12 [ END ]"); - + LOGGER.warn("Test 12 [ END ]"); + } - + @Test @Order(13) public void testConnectAndTransmit13() { - Log.warning("Test 13 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 13 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect13(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 131"; + Assertions.assertEquals(1, sender.signalEvent.size()); + final String testData1 = "MUST receive this data... 131"; sender.sendEvent(testData1); Assertions.assertEquals(testData1, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // remove connection (check auto remove)... receiver = null; System.gc(); - String testData6 = "MUST NOT receive this data... 666"; + final String testData6 = "MUST NOT receive this data... 666"; sender.sendEvent(testData6); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 13 [ END ]"); - - } + LOGGER.warn("Test 13 [ END ]"); + } + @Test public void testClearConnection() { - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); + final EmiterSimple sender = new EmiterSimple(); + final ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.signalEvent.clear(); } } diff --git a/test/src/test/atriasoft/esignal/TestSignalEmpty.java b/test/src/test/atriasoft/esignal/TestSignalEmpty.java index 9025496..781d937 100644 --- a/test/src/test/atriasoft/esignal/TestSignalEmpty.java +++ b/test/src/test/atriasoft/esignal/TestSignalEmpty.java @@ -12,31 +12,36 @@ import java.lang.ref.WeakReference; import org.atriasoft.esignal.Connection; import org.atriasoft.esignal.SignalEmpty; - -import org.junit.Test; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; //import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @TestMethodOrder(OrderAnnotation.class) public class TestSignalEmpty { + static final Logger LOGGER = LoggerFactory.getLogger(TestSignalEmpty.class); class EmiterSimple { public SignalEmpty signalEvent = new SignalEmpty(); + public void sendEvent() { this.signalEvent.emit(); } } + static class ReceiverSimple implements AutoCloseable { private boolean dataReceive = false; - ReceiverSimple() { - } + + ReceiverSimple() {} // record consumer private Runnable tmpConsumer1 = null; private Connection tmpConnect = null; + @Override public void close() { this.tmpConsumer1 = null; @@ -46,42 +51,47 @@ public class TestSignalEmpty { } this.dataReceive = false; } + public void disconnectConnection() { this.tmpConnect.close(); } + public boolean isConnected() { return this.tmpConnect.isConnected(); } - - + public void connect1(final EmiterSimple other) { - WeakReference self = new WeakReference(this); + final WeakReference self = new WeakReference<>(this); this.tmpConnect = other.signalEvent.connect(() -> { - self.get().onData(); - }); + self.get().onData(); + }); System.gc(); } + public void connect2(final EmiterSimple other) { - // the solo lambda will not depend on the object => the remove must be done manually... + // the solo lambda will not depend on the object => the remove must be done manually... this.tmpConnect = other.signalEvent.connect(() -> { - Log.error("lambda receive: "); - }); + LOGGER.error("lambda receive: "); + }); System.gc(); } + public void connect3(final EmiterSimple other) { // we reference the local object, then the lambda is alive while the object is alive... - this.tmpConnect =other.signalEvent.connect(() -> { - Log.error("lambda receive: "); - this.dataReceive = true; - }); + this.tmpConnect = other.signalEvent.connect(() -> { + LOGGER.error("lambda receive: "); + this.dataReceive = true; + }); System.gc(); } + public void connect4(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(() -> { - onData(); - }); + onData(); + }); System.gc(); } + public void connect5(final EmiterSimple other) { this.tmpConsumer1 = this::onData; other.signalEvent.connectWeak(this.tmpConsumer1); @@ -94,10 +104,10 @@ public class TestSignalEmpty { } public void connect6(final EmiterSimple other) { - // the solo lambda will not depend on the object => the remove must be done manually... + // the solo lambda will not depend on the object => the remove must be done manually... other.signalEvent.connectAutoRemoveObject(this, () -> { - Log.error("lambda receive: "); - }); + LOGGER.error("lambda receive: "); + }); System.gc(); } @@ -111,10 +121,9 @@ public class TestSignalEmpty { } public void onData() { - Log.error("Retrive data : "); - this.dataReceive = true; + LOGGER.error("Retrive data : "); + this.dataReceive = true; } - public void connect8(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(this, ReceiverSimple::onDataStatic); @@ -126,14 +135,12 @@ public class TestSignalEmpty { System.gc(); } - public static void onDataStatic(final Object local) { - ReceiverSimple self = (ReceiverSimple)local; - Log.error("Retrive data : "); - self.dataReceive = true; + final ReceiverSimple self = (ReceiverSimple) local; + LOGGER.error("Retrive data : "); + self.dataReceive = true; } - public void connect10(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(this, ReceiverSimple::onDataStatic2); System.gc(); @@ -145,31 +152,28 @@ public class TestSignalEmpty { } public static void onDataStatic2(final ReceiverSimple self) { - Log.error("Retrive data : "); - self.dataReceive = true; + LOGGER.error("Retrive data : "); + self.dataReceive = true; } public void connect12(final EmiterSimple other) { this.tmpConnect = other.signalEvent.connect(this, (final ReceiverSimple self) -> { - Log.error("Retrive data : "); - self.dataReceive = true; + LOGGER.error("Retrive data : "); + self.dataReceive = true; }); System.gc(); } public void connect13(final EmiterSimple other) { other.signalEvent.connectAuto(this, (final ReceiverSimple self) -> { - Log.error("Retrive data : "); - self.dataReceive = true; + LOGGER.error("Retrive data : "); + self.dataReceive = true; }); System.gc(); } - - - - + public boolean getDataAndClean() { - boolean tmp = this.dataReceive; + final boolean tmp = this.dataReceive; this.dataReceive = false; return tmp; } @@ -179,12 +183,12 @@ public class TestSignalEmpty { @Test @Order(1) public void testConnectAndTransmit1() { - Log.warning("Test 1 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 1 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect1(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); receiver = null; @@ -193,18 +197,19 @@ public class TestSignalEmpty { sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 1 [ END ]"); + LOGGER.warn("Test 1 [ END ]"); } + @Test @Order(2) public void testConnectAndTransmit2() { - Log.warning("Test 2 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 2 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect2(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); // No data stored ... assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -214,18 +219,18 @@ public class TestSignalEmpty { sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 2 [ END ]"); + LOGGER.warn("Test 2 [ END ]"); } @Test @Order(3) public void testConnectAndTransmit3() { - Log.warning("Test 3 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 3 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect3(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -236,22 +241,22 @@ public class TestSignalEmpty { sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 3 [ END ]"); + LOGGER.warn("Test 3 [ END ]"); } @Test @Order(4) public void testConnectAndTransmit4() { - Log.warning("Test 4 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 4 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect4(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); // Need to close ==> capture Of this receiver.close(); receiver = null; @@ -259,34 +264,34 @@ public class TestSignalEmpty { sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 4 [ END ]"); + LOGGER.warn("Test 4 [ END ]"); } @Test @Order(5) public void testConnectAndTransmit5() { - Log.warning("Test 5 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 5 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect5(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); // remove connection receiver.disconnectConsumer1(sender); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); sender.sendEvent(); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect5(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -297,40 +302,41 @@ public class TestSignalEmpty { sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 5 [ END ]"); + LOGGER.warn("Test 5 [ END ]"); } + @Test @Order(6) public void testConnectAndTransmit6() { - Log.warning("Test 6 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 6 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); receiver.connect6(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); //assertEquals(true, receiver.getDataAndClean()); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); receiver = null; System.gc(); sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 6 [ END ]"); + LOGGER.warn("Test 6 [ END ]"); } @Test @Order(7) public void testConnectAndTransmit7() { - Log.warning("Test 7 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 7 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -341,12 +347,12 @@ public class TestSignalEmpty { System.gc(); sender.sendEvent(); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -354,15 +360,15 @@ public class TestSignalEmpty { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); sender.sendEvent(); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -374,20 +380,20 @@ public class TestSignalEmpty { sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 7 [ END ]"); + LOGGER.warn("Test 7 [ END ]"); } @Test @Order(8) public void testConnectAndTransmit8() { - Log.warning("Test 8 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 8 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect8(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -398,12 +404,12 @@ public class TestSignalEmpty { System.gc(); sender.sendEvent(); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect8(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -411,15 +417,15 @@ public class TestSignalEmpty { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); sender.sendEvent(); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect8(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -429,20 +435,20 @@ public class TestSignalEmpty { sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 8 [ END ]"); + LOGGER.warn("Test 8 [ END ]"); } @Test @Order(9) public void testConnectAndTransmit9() { - Log.warning("Test 9 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 9 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect9(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -452,20 +458,20 @@ public class TestSignalEmpty { sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 9 [ END ]"); + LOGGER.warn("Test 9 [ END ]"); } @Test @Order(10) public void testConnectAndTransmit10() { - Log.warning("Test 10 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 10 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect10(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -476,12 +482,12 @@ public class TestSignalEmpty { System.gc(); sender.sendEvent(); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect10(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -489,15 +495,15 @@ public class TestSignalEmpty { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); sender.sendEvent(); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect10(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -507,20 +513,20 @@ public class TestSignalEmpty { sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 10 [ END ]"); + LOGGER.warn("Test 10 [ END ]"); } @Test @Order(11) public void testConnectAndTransmit11() { - Log.warning("Test 11 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 11 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect11(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -530,20 +536,20 @@ public class TestSignalEmpty { sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 11 [ END ]"); + LOGGER.warn("Test 11 [ END ]"); } @Test @Order(12) public void testConnectAndTransmit12() { - Log.warning("Test 12 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 12 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect12(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -554,12 +560,12 @@ public class TestSignalEmpty { System.gc(); sender.sendEvent(); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect12(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -567,15 +573,15 @@ public class TestSignalEmpty { // remove connection receiver.disconnectConnection(); Assertions.assertEquals(false, receiver.isConnected()); - Assertions.assertEquals(0, sender.signalEvent.size()); + Assertions.assertEquals(0, sender.signalEvent.size()); System.gc(); sender.sendEvent(); Assertions.assertEquals(false, receiver.getDataAndClean()); // reconnect (step 2 receiver.connect12(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -585,20 +591,20 @@ public class TestSignalEmpty { sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 12 [ END ]"); + LOGGER.warn("Test 12 [ END ]"); } @Test @Order(13) public void testConnectAndTransmit13() { - Log.warning("Test 13 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); + LOGGER.warn("Test 13 [BEGIN]"); + final EmiterSimple sender = new EmiterSimple(); ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect13(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); - + Assertions.assertEquals(1, sender.signalEvent.size()); + sender.sendEvent(); Assertions.assertEquals(true, receiver.getDataAndClean()); Assertions.assertEquals(1, sender.signalEvent.size()); @@ -608,17 +614,17 @@ public class TestSignalEmpty { sender.sendEvent(); Assertions.assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 13 [ END ]"); + LOGGER.warn("Test 13 [ END ]"); } @Test public void testClearConnection() { - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); + final EmiterSimple sender = new EmiterSimple(); + final ReceiverSimple receiver = new ReceiverSimple(); //connect step 1 receiver.connect7(sender); - Assertions.assertEquals(1, sender.signalEvent.size()); + Assertions.assertEquals(1, sender.signalEvent.size()); sender.signalEvent.clear(); } }