Skip to content

Commit

Permalink
enable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Plotnikov committed Nov 27, 2023
1 parent c1f9eef commit 078df4f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 59 deletions.
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
25 changes: 4 additions & 21 deletions src/main/java/com/exactpro/th2/FixHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer> retransmissionFlags = List.of(POSS_RESEND_TAG, POSS_DUP_TAG);

private final Random random = new Random();
private final AtomicInteger msgSeqNum = new AtomicInteger(0);
Expand Down Expand Up @@ -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<String, String>(), 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);
Expand Down Expand Up @@ -976,15 +958,17 @@ public void onOutgoingUpdateTag(@NotNull ByteBuf message, @NotNull Map<String, S
}

FixField msgSeqNum = findField(message, MSG_SEQ_NUM_TAG, US_ASCII, bodyLength);
int msgSeqNumValue = this.msgSeqNum.incrementAndGet();

if (msgSeqNum == null) {
int msgSeqNumValue = this.msgSeqNum.incrementAndGet();

if (msgType != null) {
msgSeqNum = msgType.insertNext(MSG_SEQ_NUM_TAG, Integer.toString(msgSeqNumValue));
} else {
msgSeqNum = bodyLength.insertNext(MSG_SEQ_NUM_TAG, Integer.toString(msgSeqNumValue));
}
} else {
msgSeqNum.setValue(Integer.toString(msgSeqNumValue));
}

FixField senderCompID = findField(message, SENDER_COMP_ID_TAG, US_ASCII, bodyLength);
Expand Down Expand Up @@ -1231,7 +1215,6 @@ private CompletableFuture<MessageID> bulkSend(IChannel channel, ByteBuf message,
onOutgoingUpdateTag(message, properties);
StrategyState strategyState = strategy.getState();

CompletableFuture<MessageID> messageID;
strategyState.updateCacheAndRunOnCondition(message, x -> x >= config.getBatchSize(), buffer -> {
try {
LOGGER.info("Sending batch of size: {}", config.getBatchSize());
Expand Down Expand Up @@ -1440,7 +1423,7 @@ private Map<String, String> logoutOnLogon(ByteBuf message, Map<String, String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import com.exactpro.th2.conn.dirty.fix.FieldDefinition
import com.exactpro.th2.constants.Constants

data class TransformMessageConfiguration(
val transformations: List<TransformationConfiguration>,
val numberOfTimesToTransform: Int = transformations.size
val transformations: List<TransformationConfiguration>
) {
private var transformationsIdx = 0
val numberOfTimesToTransform: Int = transformations.size
fun getNextTransformation(): TransformationConfiguration {
return transformations[transformationsIdx++ % numberOfTimesToTransform]
}
Expand Down
15 changes: 6 additions & 9 deletions src/test/java/com/exactpro/th2/FixHandlerSendTimeoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,8 +48,7 @@ void sendTimeoutOnConnectionOpen() {
any(),
anyBoolean(),
anyLong(),
anyInt(),
anyVararg()
anyInt()
))
.thenReturn(channelMock);
Mockito.when(channelMock.open())
Expand Down Expand Up @@ -90,8 +88,7 @@ void sendTimeoutOnSessionEnabled() {
any(),
anyBoolean(),
anyLong(),
anyInt(),
anyVararg()
anyInt()
))
.thenReturn(channelMock);
Mockito.when(channelMock.open())
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/com/exactpro/th2/RecoveryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
59 changes: 38 additions & 21 deletions src/test/kotlin/com/exactpro/th2/conn/dirty/fix/TestStrategies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever


@Disabled
class TestStrategies {

private class TestContext(
Expand All @@ -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)
Expand Down Expand Up @@ -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 ->
Expand Down Expand Up @@ -403,7 +422,6 @@ class TestStrategies {
}

@Test
@Disabled
fun testClientOutage() {
val defaultRuleDuration = Duration.of(2, ChronoUnit.SECONDS)
val businessRuleDuration = Duration.of(6, ChronoUnit.SECONDS)
Expand Down Expand Up @@ -452,7 +470,6 @@ class TestStrategies {
}

@Test
@Disabled
fun testPartialClientOutage() {
val defaultRuleDuration = Duration.of(2, ChronoUnit.SECONDS)
val businessRuleDuration = Duration.of(6, ChronoUnit.SECONDS)
Expand Down

0 comments on commit 078df4f

Please sign in to comment.