diff --git a/.classpath b/.classpath index a25b393..71d2e6b 100644 --- a/.classpath +++ b/.classpath @@ -23,32 +23,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -58,7 +33,37 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore index d075be7..dfd7070 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,28 @@ -/bin/ -/Operator/ -/DrawerProperties/ -*.pdfd -*.dbc -SchedulerConfig.txt -scenicView.properties -ScenariumConfig.txt +# ---> Java +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + *.class *~ *.bck @@ -15,3 +32,10 @@ build.number /.settings/ /junit/ /target/ + +*.pdfd +*.dbc +SchedulerConfig.txt +scenicView.properties +ScenariumConfig.txt +*.blend* diff --git a/src/module-info.java b/src/module-info.java index 74d7d8b..4f1801c 100644 --- a/src/module-info.java +++ b/src/module-info.java @@ -16,8 +16,7 @@ open module org.atriasoft.ewol { exports org.atriasoft.ewol.widget; //exports org.atriasoft.ewol.widget.meta; - exports org.atriasoft.esignal; - + requires transitive org.atriasoft.esignal; requires transitive org.atriasoft.iogami; requires transitive org.atriasoft.gale; requires transitive org.atriasoft.etk; diff --git a/src/org/atriasoft/esignal/Connection.java b/src/org/atriasoft/esignal/Connection.java deleted file mode 100644 index 619d541..0000000 --- a/src/org/atriasoft/esignal/Connection.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.atriasoft.esignal; - -import java.lang.ref.WeakReference; - -public class Connection implements AutoCloseable { - protected WeakReference connection; - - public void connectionIsRemovedBySignal() { - connection = null; - } - - public void disconnect() { - close(); - } - - public Connection( final ConnectionRemoveInterface object ) { - this.connection = new WeakReference<>(object); - } - - public Connection() { - this.connection = null; - } - - @Override - public void close() { - if (this.connection == null) { - return; - } - ConnectionRemoveInterface tmp = this.connection.get(); - if (tmp == null) { - return; - } - tmp.disconnect(this); - this.connection = null; - } - - public boolean isConnected() { - if (this.connection == null) { - return false; - } - ConnectionRemoveInterface tmp = this.connection.get(); - if (tmp == null) { - return false; - } - return true; - } -} diff --git a/src/org/atriasoft/esignal/ConnectionRemoveInterface.java b/src/org/atriasoft/esignal/ConnectionRemoveInterface.java deleted file mode 100644 index fe80970..0000000 --- a/src/org/atriasoft/esignal/ConnectionRemoveInterface.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.atriasoft.esignal; - -public interface ConnectionRemoveInterface { - void disconnect(final Connection connection); -} diff --git a/src/org/atriasoft/esignal/Signal.java b/src/org/atriasoft/esignal/Signal.java deleted file mode 100644 index 7a148e2..0000000 --- a/src/org/atriasoft/esignal/Signal.java +++ /dev/null @@ -1,172 +0,0 @@ -package org.atriasoft.esignal; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.function.Consumer; - -class ConnectedElement { - protected final WeakReference> consumer; - - public ConnectedElement(final Consumer consumer) { - this.consumer = new WeakReference>(consumer); - } - - public Consumer getConsumer() { - return this.consumer.get(); - } - - public boolean isCompatibleWith(final Object elem) { - /* - Object out = this.reference.get(); - if (out == elem) { - return true; - } - return false; - */ - return false; - } - - public void disconnect() { - - } -} - -class ConnectedElementDynamic extends ConnectedElement { - protected final WeakReference linkedObject; - - public ConnectedElementDynamic(Object linkedObject, final Consumer consumer) { - super(consumer); - this.linkedObject = new WeakReference(linkedObject); - } - - @Override - public Consumer getConsumer() { - if (this.linkedObject.get() == null) { - return null; - } - return this.consumer.get(); - } - - @Override - public boolean isCompatibleWith(final Object elem) { - if (super.isCompatibleWith(elem)) { - return true; - } - Object obj = this.linkedObject.get(); - if (obj == elem) { - return true; - } - return false; - } - - @Override - public void disconnect() { - Object obj = this.linkedObject.get(); - if (obj == null) { - return; - } - if (obj instanceof Connection tmp) { - tmp.connectionIsRemovedBySignal(); - } - } -} - -public class Signal implements ConnectionRemoveInterface { - List> data = new ArrayList<>(); - - public void clear() { - List> data2 = data; - synchronized(this.data) { - this.data = new ArrayList<>(); - } - final Iterator> iterator = this.data2.iterator(); - while (iterator.hasNext()) { - final ConnectedElement elem = iterator.next(); - elem.disconnect(); - } - } - - public void connect(final Consumer function) { - synchronized(this.data) { - this.data.add(new ConnectedElement(function)); - } - } -// public void disconnect(final Consumer obj) { -// synchronized(this.data) { -// final Iterator> iterator = this.data.iterator(); -// while (iterator.hasNext()) { -// final ConnectedElement elem = iterator.next(); -// if (elem.isCompatibleWith(obj)) { -// iterator.remove(); -// } -// } -// } -// } - public Connection connectDynamic(final Consumer function) { - Connection out = new Connection(this); - synchronized(this.data) { - this.data.add(new ConnectedElementDynamic(out, function)); - } - return out; - } - public void connectAutoRemoveObject(Object reference, final Consumer function) { - synchronized(this.data) { - this.data.add(new ConnectedElementDynamic(reference, function)); - } - } - - @Override - public void disconnect(final Connection connection) { - synchronized(this.data) { - final Iterator> iterator = this.data.iterator(); - while (iterator.hasNext()) { - final ConnectedElement elem = iterator.next(); - if (elem.isCompatibleWith(connection)) { - elem.disconnect(); - iterator.remove(); - } - } - } - } - - public void emit(final T value) { - List> tmp; - // clean the list: - synchronized(this.data) { - final Iterator> iterator = this.data.iterator(); - while (iterator.hasNext()) { - final ConnectedElement elem = iterator.next(); - Object tmpObject = elem.getConsumer(); - if (tmpObject == null) { - elem.disconnect(); - iterator.remove(); - } - } - // simple optimization: - if (this.data.isEmpty()) { - return; - } - // clone the list to permit to have asynchronous remove call - tmp = new ArrayList<>(this.data); - } - // real call elements - { - final Iterator> iterator = tmp.iterator(); - while (iterator.hasNext()) { - final ConnectedElement elem = iterator.next(); - Consumer tmpObject = elem.getConsumer(); - if (tmpObject == null) { - continue; - } - tmpObject.accept(value); - } - } - } - - public int size() { - return this.data.size(); - } - -} diff --git a/src/org/atriasoft/esignal/SignalEmpty.java b/src/org/atriasoft/esignal/SignalEmpty.java deleted file mode 100644 index 6a86dc3..0000000 --- a/src/org/atriasoft/esignal/SignalEmpty.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.atriasoft.esignal; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -class ConnectedElementEmpty { - private final WeakReference reference; - private final Runnable runnable; - - public ConnectedElementEmpty(final WeakReference reference, final Runnable runnable) { - this.reference = reference; - this.runnable = runnable; - } - - public WeakReference getReference() { - return this.reference; - } - - public Runnable getRunner() { - return this.runnable; - } - -} - -public class SignalEmpty { - - List data = new ArrayList<>(); - - public void clear(final Object obj) { - - } - - public Connection connect(final Object reference, final Runnable runnable) { - - return null; - } - - public void disconnect(final Connection connection) { - - } - - public void disconnect(final Object obj) { - - } - - public void emit() { - final Iterator iterator = this.data.iterator(); - while (iterator.hasNext()) { - final ConnectedElementEmpty elem = iterator.next(); - if (elem.getReference().get() == null) { - iterator.remove(); - } - elem.getRunner().run(); - } - } - - public int size() { - return this.data.size(); - } -} diff --git a/old_widget/Button.java b/src/org/atriasoft/ewol/widget/Button.java similarity index 100% rename from old_widget/Button.java rename to src/org/atriasoft/ewol/widget/Button.java diff --git a/test/src/test/atriasoft/esignal/Log.java b/test/src/test/atriasoft/esignal/Log.java deleted file mode 100644 index 9d03c58..0000000 --- a/test/src/test/atriasoft/esignal/Log.java +++ /dev/null @@ -1,59 +0,0 @@ -package test.atriasoft.esignal; - -import io.scenarium.logger.LogLevel; -import io.scenarium.logger.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/TestSignal.java b/test/src/test/atriasoft/esignal/TestSignal.java deleted file mode 100644 index 5761657..0000000 --- a/test/src/test/atriasoft/esignal/TestSignal.java +++ /dev/null @@ -1,301 +0,0 @@ -/******************************************************************************* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * Contributors: - * Edouard DUPIN - initial API and implementation - ******************************************************************************/ -package test.atriasoft.esignal; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import io.scenarium.logger.Logger; - -import org.atriasoft.esignal.Connection; -import org.atriasoft.esignal.Signal; -import org.junit.Test; -import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; -import org.junit.jupiter.api.Order; -//import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestMethodOrder; - -@TestMethodOrder(OrderAnnotation.class) -public class TestSignal { - - class EmiterSimple { - public Signal signalEvent = new Signal(); - public void sendEvent(String value) { - signalEvent.emit(value); - } - } - class ReceiverSimple { - private String dataReceive = null; - ReceiverSimple() { - } - public void connect1(EmiterSimple other) { - WeakReference tmpp = new WeakReference(this); - other.signalEvent.connect(data -> { - tmpp.get().onData(data); - }); - } - public void connect2(EmiterSimple other) { - // the solo lambda will not depend on the object => the remove must be done manually... - other.signalEvent.connect(data -> { - Log.error("lambda receive: " + data); - }); - } - public void connect3(EmiterSimple other) { - // we reference the local object, then the lambda is alive while the object is alive... - other.signalEvent.connect(data -> { - Log.error("lambda receive: " + data); - this.dataReceive = data; - }); - } - public void connect4(EmiterSimple other) { - other.signalEvent.connect(data -> { - onData(data); - }); - } - public void connect5(EmiterSimple other) { - other.signalEvent.connect(this::onData); - } -// Does not work at all: -// public void disconnect5(EmiterSimple other) { -// other.signalEvent.disconnect(this::onData); -// } - - public void connect6(EmiterSimple other) { - // 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); - }); - } - private Connection tmpConnect = null; - - public void connect7(EmiterSimple other) { - tmpConnect = other.signalEvent.connectDynamic(this::onData); - } - - public void disconnect7(EmiterSimple other) { - other.signalEvent.disconnect(tmpConnect); - } - - public void disconnect72() { - tmpConnect.disconnect(); - } - public boolean isConnected() { - return tmpConnect.isConnected(); - } - - public void onData(String data) { - Log.error("Retrive data : " + data); - dataReceive = data; - } - public String getDataAndClean() { - String tmp = dataReceive; - dataReceive = null; - return tmp; - } - - } - - @Test - @Order(1) - public void testConnectAndTransmit1() { - Log.warning("Test 1 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); - receiver.connect1(sender); - assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; - sender.sendEvent(testData1); - assertEquals(testData1, receiver.getDataAndClean()); - receiver = null; - assertEquals(1, sender.signalEvent.size()); - System.gc(); - String testData2 = "MUST NOT receive this data..."; - sender.sendEvent(testData2); - assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 1 [ END ]"); - - } - @Test - @Order(2) - public void testConnectAndTransmit2() { - Log.warning("Test 2 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); - receiver.connect2(sender); - assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; - sender.sendEvent(testData1); - // No data stored ... assertEquals(testData1, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - receiver = null; - System.gc(); - String testData2 = "Solo Lambda MUST receive this data..."; - sender.sendEvent(testData2); - assertEquals(1, sender.signalEvent.size()); - Log.warning("Test 2 [ END ]"); - } - - @Test - @Order(3) - public void testConnectAndTransmit3() { - Log.warning("Test 3 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); - receiver.connect3(sender); - assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; - sender.sendEvent(testData1); - assertEquals(testData1, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - receiver = null; - System.gc(); - String testData2 = "MUST NOT receive this data..."; - sender.sendEvent(testData2); - assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 3 [ END ]"); - - } - - @Test - @Order(4) - public void testConnectAndTransmit4() { - Log.warning("Test 4 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); - receiver.connect4(sender); - assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; - sender.sendEvent(testData1); - assertEquals(testData1, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - receiver = null; - System.gc(); - String testData2 = "MUST NOT receive this data..."; - sender.sendEvent(testData2); - assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 4 [ END ]"); - - } - - @Test - @Order(5) - public void testConnectAndTransmit5() { - Log.warning("Test 5 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); - //connect step 1 - receiver.connect5(sender); - assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; - sender.sendEvent(testData1); - assertEquals(testData1, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - // remove connection -// receiver.disconnect5(sender); -// assertEquals(0, sender.signalEvent.size()); -// System.gc(); -// String testData2 = "MUST NOT receive this data... 222"; -// sender.sendEvent(testData2); -// assertEquals(null, receiver.getDataAndClean()); -// // reconnect (step 2 -// receiver.connect5(sender); -// assertEquals(1, sender.signalEvent.size()); -// String testData3 = "MUST receive this data... 333"; -// sender.sendEvent(testData3); -// assertEquals(testData3, receiver.getDataAndClean()); -// assertEquals(1, sender.signalEvent.size()); - // check auto remove... - receiver = null; - System.gc(); - String testData4 = "MUST NOT receive this data... 444"; - sender.sendEvent(testData4); - assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 5 [ END ]"); - - } - @Test - @Order(6) - public void testConnectAndTransmit6() { - Log.warning("Test 6 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); - receiver.connect6(sender); - assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; - sender.sendEvent(testData1); - //assertEquals(testData1, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - receiver = null; - System.gc(); - String testData2 = "MUST NOT receive this data..."; - sender.sendEvent(testData2); - assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 6 [ END ]"); - - } - - @Test - @Order(7) - public void testConnectAndTransmit7() { - Log.warning("Test 7 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); - //connect step 1 - receiver.connect7(sender); - assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; - sender.sendEvent(testData1); - assertEquals(testData1, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - assertEquals(true, receiver.isConnected()); - // remove connection - receiver.disconnect7(sender); - assertEquals(false, receiver.isConnected()); - System.gc(); - String testData2 = "MUST NOT receive this data... 222"; - sender.sendEvent(testData2); - assertEquals(0, sender.signalEvent.size()); - assertEquals(null, receiver.getDataAndClean()); - // reconnect (step 2 - receiver.connect7(sender); - assertEquals(1, sender.signalEvent.size()); - String testData3 = "MUST receive this data... 333"; - sender.sendEvent(testData3); - assertEquals(testData3, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - assertEquals(true, receiver.isConnected()); - // remove connection - receiver.disconnect72(); - assertEquals(false, receiver.isConnected()); - assertEquals(0, sender.signalEvent.size()); - System.gc(); - String testData4 = "MUST NOT receive this data... 444"; - sender.sendEvent(testData4); - assertEquals(null, receiver.getDataAndClean()); - // reconnect (step 2 - receiver.connect7(sender); - assertEquals(1, sender.signalEvent.size()); - String testData5 = "MUST receive this data... 555"; - sender.sendEvent(testData5); - assertEquals(testData5, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - // check auto remove... - receiver = null; - System.gc(); - String testData6 = "MUST NOT receive this data... 666"; - sender.sendEvent(testData6); - assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 7 [ END ]"); - - } - -} diff --git a/test/src/test/atriasoft/esignal/TestSignalType.java b/test/src/test/atriasoft/esignal/TestSignalType.java deleted file mode 100644 index 2612572..0000000 --- a/test/src/test/atriasoft/esignal/TestSignalType.java +++ /dev/null @@ -1,301 +0,0 @@ -/******************************************************************************* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * Contributors: - * Edouard DUPIN - initial API and implementation - ******************************************************************************/ -package test.atriasoft.esignal; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.List; - -import io.scenarium.logger.Logger; - -import org.atriasoft.esignal.Connection; -import org.atriasoft.esignal.Signal; -import org.junit.Test; -import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; -import org.junit.jupiter.api.Order; -//import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestMethodOrder; - -@TestMethodOrder(OrderAnnotation.class) -public class TestSignalType { - - class EmiterSimple { - public Signal signalEvent = new Signal(); - public void sendEvent(String value) { - signalEvent.emit(value); - } - } - class ReceiverSimple { - private String dataReceive = null; - ReceiverSimple() { - } - public void connect1(EmiterSimple other) { - WeakReference tmpp = new WeakReference(this); - other.signalEvent.connect(data -> { - tmpp.get().onData(data); - }); - } - public void connect2(EmiterSimple other) { - // the solo lambda will not depend on the object => the remove must be done manually... - other.signalEvent.connect(data -> { - Log.error("lambda receive: " + data); - }); - } - public void connect3(EmiterSimple other) { - // we reference the local object, then the lambda is alive while the object is alive... - other.signalEvent.connect(data -> { - Log.error("lambda receive: " + data); - this.dataReceive = data; - }); - } - public void connect4(EmiterSimple other) { - other.signalEvent.connect(data -> { - onData(data); - }); - } - public void connect5(EmiterSimple other) { - other.signalEvent.connect(this::onData); - } -// Does not work at all: -// public void disconnect5(EmiterSimple other) { -// other.signalEvent.disconnect(this::onData); -// } - - public void connect6(EmiterSimple other) { - // 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); - }); - } - private Connection tmpConnect = null; - - public void connect7(EmiterSimple other) { - tmpConnect = other.signalEvent.connectDynamic(this::onData); - } - - public void disconnect7(EmiterSimple other) { - other.signalEvent.disconnect(tmpConnect); - } - - public void disconnect72() { - tmpConnect.disconnect(); - } - public boolean isConnected() { - return tmpConnect.isConnected(); - } - - public void onData(String data) { - Log.error("Retrive data : " + data); - dataReceive = data; - } - public String getDataAndClean() { - String tmp = dataReceive; - dataReceive = null; - return tmp; - } - - } - - @Test - @Order(1) - public void testConnectAndTransmit1() { - Log.warning("Test 1 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); - receiver.connect1(sender); - assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; - sender.sendEvent(testData1); - assertEquals(testData1, receiver.getDataAndClean()); - receiver = null; - assertEquals(1, sender.signalEvent.size()); - System.gc(); - String testData2 = "MUST NOT receive this data..."; - sender.sendEvent(testData2); - assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 1 [ END ]"); - - } - @Test - @Order(2) - public void testConnectAndTransmit2() { - Log.warning("Test 2 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); - receiver.connect2(sender); - assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; - sender.sendEvent(testData1); - // No data stored ... assertEquals(testData1, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - receiver = null; - System.gc(); - String testData2 = "Solo Lambda MUST receive this data..."; - sender.sendEvent(testData2); - assertEquals(1, sender.signalEvent.size()); - Log.warning("Test 2 [ END ]"); - } - - @Test - @Order(3) - public void testConnectAndTransmit3() { - Log.warning("Test 3 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); - receiver.connect3(sender); - assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; - sender.sendEvent(testData1); - assertEquals(testData1, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - receiver = null; - System.gc(); - String testData2 = "MUST NOT receive this data..."; - sender.sendEvent(testData2); - assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 3 [ END ]"); - - } - - @Test - @Order(4) - public void testConnectAndTransmit4() { - Log.warning("Test 4 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); - receiver.connect4(sender); - assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; - sender.sendEvent(testData1); - assertEquals(testData1, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - receiver = null; - System.gc(); - String testData2 = "MUST NOT receive this data..."; - sender.sendEvent(testData2); - assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 4 [ END ]"); - - } - - @Test - @Order(5) - public void testConnectAndTransmit5() { - Log.warning("Test 5 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); - //connect step 1 - receiver.connect5(sender); - assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; - sender.sendEvent(testData1); - assertEquals(testData1, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - // remove connection -// receiver.disconnect5(sender); -// assertEquals(0, sender.signalEvent.size()); -// System.gc(); -// String testData2 = "MUST NOT receive this data... 222"; -// sender.sendEvent(testData2); -// assertEquals(null, receiver.getDataAndClean()); -// // reconnect (step 2 -// receiver.connect5(sender); -// assertEquals(1, sender.signalEvent.size()); -// String testData3 = "MUST receive this data... 333"; -// sender.sendEvent(testData3); -// assertEquals(testData3, receiver.getDataAndClean()); -// assertEquals(1, sender.signalEvent.size()); - // check auto remove... - receiver = null; - System.gc(); - String testData4 = "MUST NOT receive this data... 444"; - sender.sendEvent(testData4); - assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 5 [ END ]"); - - } - @Test - @Order(6) - public void testConnectAndTransmit6() { - Log.warning("Test 6 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); - receiver.connect6(sender); - assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data..."; - sender.sendEvent(testData1); - //assertEquals(testData1, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - receiver = null; - System.gc(); - String testData2 = "MUST NOT receive this data..."; - sender.sendEvent(testData2); - assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 6 [ END ]"); - - } - - @Test - @Order(7) - public void testConnectAndTransmit7() { - Log.warning("Test 7 [BEGIN]"); - EmiterSimple sender = new EmiterSimple(); - ReceiverSimple receiver = new ReceiverSimple(); - //connect step 1 - receiver.connect7(sender); - assertEquals(1, sender.signalEvent.size()); - String testData1 = "MUST receive this data... 111"; - sender.sendEvent(testData1); - assertEquals(testData1, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - assertEquals(true, receiver.isConnected()); - // remove connection - receiver.disconnect7(sender); - assertEquals(false, receiver.isConnected()); - System.gc(); - String testData2 = "MUST NOT receive this data... 222"; - sender.sendEvent(testData2); - assertEquals(0, sender.signalEvent.size()); - assertEquals(null, receiver.getDataAndClean()); - // reconnect (step 2 - receiver.connect7(sender); - assertEquals(1, sender.signalEvent.size()); - String testData3 = "MUST receive this data... 333"; - sender.sendEvent(testData3); - assertEquals(testData3, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - assertEquals(true, receiver.isConnected()); - // remove connection - receiver.disconnect72(); - assertEquals(false, receiver.isConnected()); - assertEquals(0, sender.signalEvent.size()); - System.gc(); - String testData4 = "MUST NOT receive this data... 444"; - sender.sendEvent(testData4); - assertEquals(null, receiver.getDataAndClean()); - // reconnect (step 2 - receiver.connect7(sender); - assertEquals(1, sender.signalEvent.size()); - String testData5 = "MUST receive this data... 555"; - sender.sendEvent(testData5); - assertEquals(testData5, receiver.getDataAndClean()); - assertEquals(1, sender.signalEvent.size()); - // check auto remove... - receiver = null; - System.gc(); - String testData6 = "MUST NOT receive this data... 666"; - sender.sendEvent(testData6); - assertEquals(0, sender.signalEvent.size()); - Log.warning("Test 7 [ END ]"); - - } - -}