Skip to content

Commit

Permalink
Merge from main
Browse files Browse the repository at this point in the history
  • Loading branch information
thangqp committed Oct 30, 2023
2 parents 043b1c0 + 530f68f commit 6aef862
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.powsybl.network.store.client.NetworkStoreService;
import org.gridsuite.ds.server.CustomApplicationContextInitializer;
import org.gridsuite.ds.server.DynamicSimulationApplication;
import org.gridsuite.ds.server.controller.utils.TestUtils;
import org.gridsuite.ds.server.service.DynamicSimulationWorkerService;
import org.gridsuite.ds.server.service.client.dynamicmapping.DynamicMappingClient;
import org.gridsuite.ds.server.service.client.timeseries.TimeSeriesClient;
Expand All @@ -35,7 +36,6 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -101,10 +101,11 @@ public void tearDown() {
OutputDestination output = getOutputDestination();
List<String> destinations = List.of(dsFailedDestination, dsResultDestination);

destinations.forEach(destination -> assertNull("Should not be any messages in queue " + destination + " : ", output.receive(100, destination)));

// purge in order to not fail the other tests
output.clear();
try {
TestUtils.assertQueuesEmptyThenClear(destinations, output);
} catch (InterruptedException e) {
throw new RuntimeException("Error while checking message queues empty", e);
}
}

protected abstract OutputDestination getOutputDestination();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void test() {

UUID runUuid = UUID.fromString(entityExchangeResult.getResponseBody().toString());

Message<byte[]> messageSwitch = output.receive(1000 * 5, dsResultDestination);
Message<byte[]> messageSwitch = output.receive(1000 * 10, dsResultDestination);
assertEquals(runUuid, UUID.fromString(messageSwitch.getHeaders().get(HEADER_RESULT_UUID).toString()));

//run the dynamic simulation on the implicit default variant
Expand All @@ -165,7 +165,7 @@ public void test() {

runUuid = UUID.fromString(entityExchangeResult.getResponseBody().toString());

messageSwitch = output.receive(1000 * 5, dsResultDestination);
messageSwitch = output.receive(1000 * 10, dsResultDestination);
assertEquals(runUuid, UUID.fromString(messageSwitch.getHeaders().get(HEADER_RESULT_UUID).toString()));

//get the calculation status
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package org.gridsuite.ds.server.controller.utils;

import org.springframework.cloud.stream.binder.test.OutputDestination;

import java.util.List;

import static org.junit.Assert.assertNull;

/**
* @author Thang PHAM <quyet-thang.pham at rte-france.com>
*/
public final class TestUtils {
private static final long TIMEOUT = 100;

private TestUtils() {

}

public static void assertQueuesEmptyThenClear(List<String> destinations, OutputDestination output) throws InterruptedException {
Thread.sleep(TIMEOUT);
try {
destinations.forEach(destination -> assertNull("Should not be any messages in queue " + destination + " : ", output.receive(0, destination)));
} catch (NullPointerException e) {
// Ignoring
} finally {
output.clear(); // purge in order to not fail the other tests
}
}
}

0 comments on commit 6aef862

Please sign in to comment.