From 078df4f719dfd2971fdfc96a5871eff6135c6e70 Mon Sep 17 00:00:00 2001 From: Denis Plotnikov Date: Mon, 27 Nov 2023 18:54:32 +0400 Subject: [PATCH] enable tests --- build.gradle | 5 +- .../java/com/exactpro/th2/FixHandler.java | 25 ++------ .../TransformMessageConfiguration.kt | 4 +- .../th2/FixHandlerSendTimeoutTest.java | 15 ++--- .../java/com/exactpro/th2/RecoveryTest.java | 8 +-- .../th2/conn/dirty/fix/TestStrategies.kt | 59 ++++++++++++------- 6 files changed, 57 insertions(+), 59 deletions(-) diff --git a/build.gradle b/build.gradle index 8063861..9573102 100644 --- a/build.gradle +++ b/build.gradle @@ -69,10 +69,11 @@ dependencies { implementation 'com.fasterxml.jackson.core:jackson-databind' implementation 'com.fasterxml.jackson.module:jackson-module-kotlin' + testImplementation 'org.mockito:mockito-core:5.4.0' testImplementation 'org.mockito:mockito-all:1.10.19' - testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5:1.7.10' + testImplementation 'org.jetbrains.kotlin:kotlin-test-junit5:1.8.10' testImplementation 'org.junit.jupiter:junit-jupiter-params:5.9.3' - testImplementation 'org.mockito.kotlin:mockito-kotlin:4.0.0' + testImplementation 'org.mockito.kotlin:mockito-kotlin:4.1.0' annotationProcessor 'com.google.auto.service:auto-service:1.0.1' kapt 'com.google.auto.service:auto-service:1.0.1' diff --git a/src/main/java/com/exactpro/th2/FixHandler.java b/src/main/java/com/exactpro/th2/FixHandler.java index b0d69b0..8674219 100644 --- a/src/main/java/com/exactpro/th2/FixHandler.java +++ b/src/main/java/com/exactpro/th2/FixHandler.java @@ -196,7 +196,6 @@ public class FixHandler implements AutoCloseable, IHandler { private static final String STRATEGY_EVENT_TYPE = "StrategyState"; private static final DateTimeFormatter formatter = DateTimeFormatter.ISO_INSTANT; private static final ObjectMapper mapper = new ObjectMapper(); - private static final List retransmissionFlags = List.of(POSS_RESEND_TAG, POSS_DUP_TAG); private final Random random = new Random(); private final AtomicInteger msgSeqNum = new AtomicInteger(0); @@ -885,23 +884,6 @@ private void recovery(int beginSeqNo, int endSeqNo, RecoveryConfig recoveryConfi } } - private void sendSequenceReset() { - StringBuilder sequenceReset = new StringBuilder(); - String time = getTime(); - setHeader(sequenceReset, MSG_TYPE_SEQUENCE_RESET, msgSeqNum.incrementAndGet(), time); - sequenceReset.append(ORIG_SENDING_TIME).append(time); - sequenceReset.append(NEW_SEQ_NO).append(msgSeqNum.get() + 1); - setChecksumAndBodyLength(sequenceReset); - - if (enabled.get()) { - channel.send(Unpooled.wrappedBuffer(sequenceReset.toString().getBytes(StandardCharsets.UTF_8)), new HashMap(), null, SendMode.HANDLE_AND_MANGLE) - .thenAcceptAsync(x -> strategy.getState().addMessageID(x), executorService); - resetHeartbeatTask(); - } else { - sendLogon(); - } - } - private void checkHeartbeat(ByteBuf message) { FixField receivedTestReqID = findField(message, TEST_REQ_ID_TAG); @@ -976,15 +958,17 @@ public void onOutgoingUpdateTag(@NotNull ByteBuf message, @NotNull Map bulkSend(IChannel channel, ByteBuf message, onOutgoingUpdateTag(message, properties); StrategyState strategyState = strategy.getState(); - CompletableFuture messageID; strategyState.updateCacheAndRunOnCondition(message, x -> x >= config.getBatchSize(), buffer -> { try { LOGGER.info("Sending batch of size: {}", config.getBatchSize()); @@ -1440,7 +1423,7 @@ private Map logoutOnLogon(ByteBuf message, Map m disconnect(strategy.getGracefulDisconnect()); if(!channel.isOpen()) channel.open().get(); } catch (Exception e) { - LOGGER.error("Error while reconnecting."); + LOGGER.error("Error while reconnecting.", e); } } else { handleLogon(message, metadata); diff --git a/src/main/kotlin/com/exactpro/th2/conn/dirty/fix/brokenconn/configuration/TransformMessageConfiguration.kt b/src/main/kotlin/com/exactpro/th2/conn/dirty/fix/brokenconn/configuration/TransformMessageConfiguration.kt index 27314d6..75a0296 100644 --- a/src/main/kotlin/com/exactpro/th2/conn/dirty/fix/brokenconn/configuration/TransformMessageConfiguration.kt +++ b/src/main/kotlin/com/exactpro/th2/conn/dirty/fix/brokenconn/configuration/TransformMessageConfiguration.kt @@ -20,10 +20,10 @@ import com.exactpro.th2.conn.dirty.fix.FieldDefinition import com.exactpro.th2.constants.Constants data class TransformMessageConfiguration( - val transformations: List, - val numberOfTimesToTransform: Int = transformations.size + val transformations: List ) { private var transformationsIdx = 0 + val numberOfTimesToTransform: Int = transformations.size fun getNextTransformation(): TransformationConfiguration { return transformations[transformationsIdx++ % numberOfTimesToTransform] } diff --git a/src/test/java/com/exactpro/th2/FixHandlerSendTimeoutTest.java b/src/test/java/com/exactpro/th2/FixHandlerSendTimeoutTest.java index 5e81642..1b4d68c 100644 --- a/src/test/java/com/exactpro/th2/FixHandlerSendTimeoutTest.java +++ b/src/test/java/com/exactpro/th2/FixHandlerSendTimeoutTest.java @@ -32,11 +32,10 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeoutException; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyBoolean; -import static org.mockito.Matchers.anyInt; -import static org.mockito.Matchers.anyLong; -import static org.mockito.Matchers.anyVararg; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.ArgumentMatchers.anyLong; class FixHandlerSendTimeoutTest { @Test @@ -49,8 +48,7 @@ void sendTimeoutOnConnectionOpen() { any(), anyBoolean(), anyLong(), - anyInt(), - anyVararg() + anyInt() )) .thenReturn(channelMock); Mockito.when(channelMock.open()) @@ -90,8 +88,7 @@ void sendTimeoutOnSessionEnabled() { any(), anyBoolean(), anyLong(), - anyInt(), - anyVararg() + anyInt() )) .thenReturn(channelMock); Mockito.when(channelMock.open()) diff --git a/src/test/java/com/exactpro/th2/RecoveryTest.java b/src/test/java/com/exactpro/th2/RecoveryTest.java index 290a929..ddfd567 100644 --- a/src/test/java/com/exactpro/th2/RecoveryTest.java +++ b/src/test/java/com/exactpro/th2/RecoveryTest.java @@ -63,7 +63,7 @@ void testSequenceResetInRange() { ) ); Mockito.when(dataProviderService.searchMessageGroups(Mockito.any())).thenAnswer( - x -> ms.searchMessages(x.getArgumentAt(0, MessageGroupsSearchRequest.class)) + x -> ms.searchMessages(x.getArgument(0, MessageGroupsSearchRequest.class)) ); channel = new Channel(settings, dataProviderService); fixHandler = channel.getFixHandler(); @@ -94,7 +94,7 @@ void testSequenceResetInsideRange() { ) ); Mockito.when(dataProviderService.searchMessageGroups(Mockito.any())).thenAnswer( - x -> ms.searchMessages(x.getArgumentAt(0, MessageGroupsSearchRequest.class)) + x -> ms.searchMessages(x.getArgument(0, MessageGroupsSearchRequest.class)) ); channel = new Channel(settings, dataProviderService); fixHandler = channel.getFixHandler(); @@ -154,7 +154,7 @@ void testSequenceResetOutOfRange() { ) ); Mockito.when(dataProviderService.searchMessageGroups(Mockito.any())).thenAnswer( - x -> ms.searchMessages(x.getArgumentAt(0, MessageGroupsSearchRequest.class)) + x -> ms.searchMessages(x.getArgument(0, MessageGroupsSearchRequest.class)) ); channel = new Channel(settings, dataProviderService); fixHandler = channel.getFixHandler(); @@ -186,7 +186,7 @@ void testSequenceResetAdminMessages() { ) ); Mockito.when(dataProviderService.searchMessageGroups(Mockito.any())).thenAnswer( - x -> ms.searchMessages(x.getArgumentAt(0, MessageGroupsSearchRequest.class)) + x -> ms.searchMessages(x.getArgument(0, MessageGroupsSearchRequest.class)) ); channel = new Channel(settings, dataProviderService); fixHandler = channel.getFixHandler(); diff --git a/src/test/kotlin/com/exactpro/th2/conn/dirty/fix/TestStrategies.kt b/src/test/kotlin/com/exactpro/th2/conn/dirty/fix/TestStrategies.kt index f501634..9d161ae 100644 --- a/src/test/kotlin/com/exactpro/th2/conn/dirty/fix/TestStrategies.kt +++ b/src/test/kotlin/com/exactpro/th2/conn/dirty/fix/TestStrategies.kt @@ -65,7 +65,6 @@ import org.mockito.kotlin.verify import org.mockito.kotlin.whenever -@Disabled class TestStrategies { private class TestContext( @@ -82,11 +81,11 @@ class TestStrategies { val testContext = createTestContext(BrokenConnConfiguration( SchedulerType.CONSECUTIVE, listOf( - RuleConfiguration(RuleType.DEFAULT, duration = Duration.of(2, ChronoUnit.SECONDS), cleanUpDuration = Duration.of(0, ChronoUnit.SECONDS)), + RuleConfiguration(RuleType.DEFAULT, duration = defaultRuleDuration, cleanUpDuration = Duration.of(0, ChronoUnit.MILLIS)), RuleConfiguration( RuleType.DISCONNECT_WITH_RECONNECT, - duration = Duration.of(4, ChronoUnit.SECONDS), - cleanUpDuration = Duration.of(1, ChronoUnit.SECONDS) + duration = businessRuleDuration, + cleanUpDuration = businessRuleCleanupDuration ), ) ), enableAdditionalHandling = false) @@ -230,21 +229,41 @@ class TestStrategies { duration = businessRuleDuration, cleanUpDuration = Duration.of(2, ChronoUnit.SECONDS), transformMessageConfiguration = TransformMessageConfiguration( - listOf(TransformationConfiguration(listOf( - Action( - replace = FieldSelector( - tag = Constants.PASSWORD_TAG, - matches = Pattern.compile("pass"), - tagOneOf = null - ), - with = FieldDefinition( - tag = Constants.PASSWORD_TAG, - value = "mangledPassword", - tagOneOf = null, - valueOneOf = null - ) - ) - ), false, "A")), 2), + listOf( + TransformationConfiguration( + listOf( + Action( + replace = FieldSelector( + tag = Constants.PASSWORD_TAG, + matches = Pattern.compile("pass"), + tagOneOf = null + ), + with = FieldDefinition( + tag = Constants.PASSWORD_TAG, + value = "mangledPassword", + tagOneOf = null, + valueOneOf = null + ) + ) + ), false, "A"), + TransformationConfiguration( + listOf( + Action( + replace = FieldSelector( + tag = Constants.PASSWORD_TAG, + matches = Pattern.compile("pass"), + tagOneOf = null + ), + with = FieldDefinition( + tag = Constants.PASSWORD_TAG, + value = "mangledPassword", + tagOneOf = null, + valueOneOf = null + ) + ) + ), false, "A") + ) + ), ), ) )) { msg, mode, mtd -> @@ -403,7 +422,6 @@ class TestStrategies { } @Test - @Disabled fun testClientOutage() { val defaultRuleDuration = Duration.of(2, ChronoUnit.SECONDS) val businessRuleDuration = Duration.of(6, ChronoUnit.SECONDS) @@ -452,7 +470,6 @@ class TestStrategies { } @Test - @Disabled fun testPartialClientOutage() { val defaultRuleDuration = Duration.of(2, ChronoUnit.SECONDS) val businessRuleDuration = Duration.of(6, ChronoUnit.SECONDS)