Skip to content

Commit 24a727f

Browse files
Merge pull request #256 from eclipse-basyx/development-propagation-wait
Waits for Message propagation in tests
2 parents 4d36e2f + f58ae43 commit 24a727f

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/MqttAASServerSuite.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import static org.junit.Assert.assertEquals;
2828
import static org.junit.Assert.assertTrue;
2929
import static org.junit.Assert.fail;
30+
3031
import java.io.IOException;
32+
3133
import org.eclipse.basyx.aas.metamodel.map.AssetAdministrationShell;
3234
import org.eclipse.basyx.aas.metamodel.map.descriptor.CustomId;
3335
import org.eclipse.basyx.components.aas.AASServerComponent;
@@ -47,6 +49,7 @@
4749
import org.junit.AfterClass;
4850
import org.junit.Before;
4951
import org.junit.Test;
52+
5053
import io.moquette.broker.Server;
5154
import io.moquette.broker.config.ClasspathResourceLoader;
5255
import io.moquette.broker.config.IConfig;
@@ -113,7 +116,7 @@ public void shellLifeCycle() {
113116
}
114117

115118
@Test
116-
public void submodelLifeCycle() {
119+
public void submodelLifeCycle() throws InterruptedException {
117120
IIdentifier shellIdentifierForSubmodel = new CustomId("shellSubmodelId");
118121
AssetAdministrationShell shell = createShell(shellIdentifierForSubmodel.getId(), shellIdentifierForSubmodel);
119122
manager.createAAS(shell, getURL());
@@ -128,6 +131,8 @@ public void submodelLifeCycle() {
128131

129132
manager.deleteSubmodel(shellIdentifierForSubmodel, submodelIdentifier);
130133

134+
waitForPropagation();
135+
131136
assertTrue(listener.getTopics().stream().anyMatch(t -> t.equals(MqttAASAPIHelper.TOPIC_REMOVESUBMODEL)));
132137
assertTrue(listener.getTopics().stream().anyMatch(t -> t.equals(MqttSubmodelAggregatorHelper.TOPIC_DELETESUBMODEL)));
133138
try {
@@ -139,6 +144,10 @@ public void submodelLifeCycle() {
139144
manager.deleteAAS(shellIdentifierForSubmodel);
140145
}
141146

147+
private void waitForPropagation() throws InterruptedException {
148+
Thread.sleep(1000);
149+
}
150+
142151
protected static BaSyxContextConfiguration createBaSyxContextConfiguration() {
143152
BaSyxContextConfiguration config = new BaSyxContextConfiguration();
144153
config.loadFromResource(BaSyxContextConfiguration.DEFAULT_CONFIG_PATH);

basyx.components/basyx.components.docker/basyx.components.AASServer/src/test/java/org/eclipse/basyx/regression/AASServer/MqttV2AASServerSuite.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,23 @@ protected static void genericSetupClass(BaSyxAASServerConfiguration serverConfig
9797
}
9898

9999
@Test
100-
public void shellLifeCycle() {
100+
public void shellLifeCycle() throws InterruptedException {
101101
MqttV2AASAggregatorTopicFactory aasAggregatorFactory = new MqttV2AASAggregatorTopicFactory(new Base64URLEncoder());
102102

103103
AssetAdministrationShell shell = createShell(shellIdentifier.getId(), shellIdentifier);
104104

105105
manager.createAAS(shell, getURL());
106106

107+
waitForPropagation();
108+
107109
assertEquals(aasAggregatorFactory.createCreateAASTopic(AAS_SERVER_ID), listener.lastTopic);
108110

109111
assertEquals(shell.getIdShort(), manager.retrieveAAS(shellIdentifier).getIdShort());
110112

111113
manager.deleteAAS(shellIdentifier);
114+
115+
waitForPropagation();
116+
112117
assertEquals(aasAggregatorFactory.createDeleteAASTopic(AAS_SERVER_ID), listener.lastTopic);
113118
try {
114119
manager.retrieveAAS(shellIdentifier);
@@ -119,7 +124,7 @@ public void shellLifeCycle() {
119124
}
120125

121126
@Test
122-
public void submodelLifeCycle() {
127+
public void submodelLifeCycle() throws InterruptedException {
123128
MqttV2SubmodelAggregatorTopicFactory submodelAggregatorFactory = new MqttV2SubmodelAggregatorTopicFactory(new Base64URLEncoder());
124129
IIdentifier shellIdentifierForSubmodel = new CustomId("shellSubmodelId");
125130
AssetAdministrationShell shell = createShell(shellIdentifierForSubmodel.getId(), shellIdentifierForSubmodel);
@@ -128,12 +133,16 @@ public void submodelLifeCycle() {
128133
Submodel submodel = createSubmodel(submodelIdentifier.getId(), submodelIdentifier);
129134
manager.createSubmodel(shellIdentifierForSubmodel, submodel);
130135

136+
waitForPropagation();
137+
131138
assertTrue(listener.getTopics().stream().anyMatch(t -> t.equals(submodelAggregatorFactory.createCreateSubmodelTopic(shell.getIdentification().getId(), AAS_SERVER_ID))));
132139

133140
assertEquals(submodel.getIdShort(), manager.retrieveSubmodel(shellIdentifierForSubmodel, submodelIdentifier).getIdShort());
134141

135142
manager.deleteSubmodel(shellIdentifierForSubmodel, submodelIdentifier);
136143

144+
waitForPropagation();
145+
137146
assertTrue(listener.getTopics().stream().anyMatch(t -> t.equals(submodelAggregatorFactory.createDeleteSubmodelTopic(shell.getIdentification().getId(), AAS_SERVER_ID))));
138147

139148
try {
@@ -145,6 +154,10 @@ public void submodelLifeCycle() {
145154
manager.deleteAAS(shellIdentifierForSubmodel);
146155
}
147156

157+
private void waitForPropagation() throws InterruptedException {
158+
Thread.sleep(1000);
159+
}
160+
148161
protected static BaSyxContextConfiguration createBaSyxContextConfiguration() {
149162
BaSyxContextConfiguration config = new BaSyxContextConfiguration();
150163
config.loadFromResource(BaSyxContextConfiguration.DEFAULT_CONFIG_PATH);

0 commit comments

Comments
 (0)