[FEAT] use Maven a build system root tool

This commit is contained in:
Edouard DUPIN 2024-06-07 09:26:18 +02:00
parent 5edc58ff08
commit 0f52b339dd
12 changed files with 868 additions and 796 deletions

View File

@ -1,36 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src">
<classpathentry including="**/*.java" kind="src" output="out/maven/classes" path="src">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry including="**/*.java" kind="src" output="out/eclipse/classes-test" path="test/src">
<classpathentry kind="src" output="out/maven/test-classes" path="test/src">
<attributes>
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="atriasoft-ewol/lib"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-15">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5">
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/atriasoft-etk">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/atriasoft-etk/lib/spotbugs-annotations-4.2.2.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="out/eclipse/classes"/>
<classpathentry kind="output" path="out/maven/classes"/>
</classpath>

View File

@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>atriasoft-esignal</name>
<name>esignal</name>
<comment></comment>
<projects>
<project>atriasoft-esignal</project>
</projects>
<buildSpec>
<buildCommand>
@ -12,24 +11,13 @@
</arguments>
</buildCommand>
<buildCommand>
<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
<filteredResources>
<filter>
<id>1646149232191</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>

123
pom.xml Normal file
View File

@ -0,0 +1,123 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.atriasoft</groupId>
<artifactId>esignal</artifactId>
<version>0.1.0</version>
<properties>
<maven.compiler.version>3.13.0</maven.compiler.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<maven.dependency.version>3.1.1</maven.dependency.version>
</properties>
<repositories>
<repository>
<id>gitea</id>
<url>https://gitea.atria-soft.org/api/packages/org.atriasoft/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitea</id>
<url>https://gitea.atria-soft.org/api/packages/org.atriasoft/maven</url>
</repository>
<snapshotRepository>
<id>gitea</id>
<url>https://gitea.atria-soft.org/api/packages/org.atriasoft/maven</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.atriasoft</groupId>
<artifactId>etk</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test/src</testSourceDirectory>
<directory>${project.basedir}/out/maven/</directory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<!--<encoding>${project.build.sourceEncoding}</encoding>-->
</configuration>
</plugin>
<!-- Create the source bundle -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- junit results -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<!-- Java-doc generation for stand-alone site -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<show>private</show>
<nohelp>true</nohelp>
</configuration>
</plugin>
</plugins>
</build>
<!-- Generate Java-docs As Part Of Project Reports -->
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<show>public</show>
</configuration>
</plugin>
</plugins>
</reporting>
</project>

View File

@ -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);
* }
* }
* }</pre>

View File

@ -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);
* }
* }
* }</pre>

View File

@ -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);
* });
* }
* }

View File

@ -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");
* });
* }
* }

View File

@ -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);
}
}

View File

@ -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<String> signalEvent = new ISignal<String>();
public ISignal<String> 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<String> 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<ReceiverSimple> self = new WeakReference<ReceiverSimple>(this);
final WeakReference<ReceiverSimple> 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();
}
}

View File

@ -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<ReceiverSimple> self = new WeakReference<ReceiverSimple>(this);
final WeakReference<ReceiverSimple> 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 ]");
}
}

View File

@ -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<String> signalEvent = new Signal<String>();
public Signal<String> 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<String> 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<ReceiverSimple> self = new WeakReference<ReceiverSimple>(this);
final WeakReference<ReceiverSimple> 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();
}
}

View File

@ -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<ReceiverSimple> self = new WeakReference<ReceiverSimple>(this);
final WeakReference<ReceiverSimple> 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();
}
}