Skip to content

Commit

Permalink
Merge remote-tracking branch 'conn-dirty-fix/master' into TS-1928
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Smirnov-Exactpro committed Jul 11, 2024
2 parents 1647d07 + 5c447b9 commit 38c9298
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 64 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/ci-unwelcome-words.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ jobs:
test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- name: Checkout tool
uses: actions/checkout@v4
with:
repository: exactpro-th2/ci-github-action
ref: master
token: ${{ secrets.PAT_CI_ACTION }}
path: ci-github-action
- name: Run CI action
uses: ./ci-github-action
with:
ref: ${{ github.sha }}
- uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
- name: Checkout tool
uses: actions/checkout@v4
with:
repository: exactpro-th2/ci-github-action
ref: master
token: ${{ secrets.PAT_CI_ACTION }}
path: ci-github-action
- name: Run CI action
uses: ./ci-github-action
with:
ref: ${{ github.sha }}
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# th2-conn-dirty-fix (1.3.0)
# th2-conn-dirty-fix (1.4.0)

This microservice allows sending and receiving messages via FIX protocol

Expand Down Expand Up @@ -333,6 +333,12 @@ spec:
memory: 100Mi
cpu: 20m
```
# Changelog

## 1.4.0

* Merged changes from [th2-conn-dirty-fix:1.7.0](https://github.com/th2-net/th2-conn-dirty-fix)

## 1.3.0

* Migrated to th2 gradle plugin `0.1.1`
Expand Down Expand Up @@ -422,4 +428,4 @@ spec:

## 0.0.2

* Supported the password encryption via `RSA` algorithm.
* Supported the password encryption via `RSA` algorithm.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
release_version=1.3.0
release_version=1.4.0
93 changes: 49 additions & 44 deletions src/test/java/com/exactpro/th2/FixHandlerSendTimeoutTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Exactpro (Exactpro Systems Limited)
* Copyright 2023-2024 Exactpro (Exactpro Systems Limited)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@
import com.exactpro.th2.conn.dirty.tcp.core.api.IChannel;
import com.exactpro.th2.conn.dirty.tcp.core.api.IHandlerContext;
import kotlin.Unit;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
Expand All @@ -48,36 +49,32 @@ void sendTimeoutOnConnectionOpen() {
any(),
anyBoolean(),
anyLong(),
anyInt()
anyInt(),
any(String[].class)
))
.thenReturn(channelMock);
Mockito.when(channelMock.open())
.thenReturn(new CompletableFuture<>()); // future never completes
var settings = new FixHandlerSettings();
settings.setPort(42);
settings.setSenderCompID("test");
settings.setPassword("test");
settings.setHost("localhost");
settings.setConnectionTimeoutOnSend(300); // 300 millis
settings.setMinConnectionTimeoutOnSend(100);
var settings = createSettings();
Mockito.when(contextMock.getSettings())
.thenReturn(settings);
var fixHandler = new FixHandler(contextMock);
fixHandler.onStart();
var exception = Assertions.assertThrows(TimeoutException.class, () ->
fixHandler.send(RawMessage.builder()
.setId(MessageId.builder()
.setDirection(Direction.OUTGOING)
.setSessionAlias("test")
.setSequence(1)
.setTimestamp(Instant.now())
.build())
.build()));
Assertions.assertEquals(
"could not open connection before timeout 300 mls elapsed",
exception.getMessage(),
"unexpected message"
);
try(var fixHandler = new FixHandler(contextMock)) {
fixHandler.onStart();
var exception = Assertions.assertThrows(TimeoutException.class, () ->
fixHandler.send(RawMessage.builder()
.setId(MessageId.builder()
.setDirection(Direction.OUTGOING)
.setSessionAlias("test")
.setSequence(1)
.setTimestamp(Instant.now())
.build())
.build()));
Assertions.assertEquals(
"could not open connection before timeout 300 mls elapsed",
exception.getMessage(),
"unexpected message"
);
}
}

@Test
Expand All @@ -90,12 +87,37 @@ void sendTimeoutOnSessionEnabled() {
any(),
anyBoolean(),
anyLong(),
anyInt()
anyInt(),
any(String[].class)
))
.thenReturn(channelMock);
Mockito.when(channelMock.open())
.thenReturn(CompletableFuture.completedFuture(Unit.INSTANCE)); // completed immediately
Mockito.when(channelMock.isOpen()).thenReturn(true);
var settings = createSettings();
Mockito.when(contextMock.getSettings())
.thenReturn(settings);
try(var fixHandler = new FixHandler(contextMock)) {
fixHandler.onStart();
var exception = Assertions.assertThrows(TimeoutException.class, () ->
fixHandler.send(RawMessage.builder()
.setId(MessageId.builder()
.setDirection(Direction.OUTGOING)
.setSessionAlias("test")
.setSequence(1)
.setTimestamp(Instant.now())
.build())
.build()));
Assertions.assertEquals(
"session was not established within 300 mls",
exception.getMessage(),
"unexpected message"
);
}
}

@NotNull
private static FixHandlerSettings createSettings() {
var settings = new FixHandlerSettings();
settings.setPort(42);
settings.setHost("localhost");
Expand All @@ -114,23 +136,6 @@ void sendTimeoutOnSessionEnabled() {
settings.setSessionStartTime(currentTime.plusMinutes(deltaMinutes * 2));
settings.setSessionEndTime(currentTime.plusMinutes(deltaMinutes));
}
Mockito.when(contextMock.getSettings())
.thenReturn(settings);
var fixHandler = new FixHandler(contextMock);
fixHandler.onStart();
var exception = Assertions.assertThrows(TimeoutException.class, () ->
fixHandler.send(RawMessage.builder()
.setId(MessageId.builder()
.setDirection(Direction.OUTGOING)
.setSessionAlias("test")
.setSequence(1)
.setTimestamp(Instant.now())
.build())
.build()));
Assertions.assertEquals(
"session was not established within 300 mls",
exception.getMessage(),
"unexpected message"
);
return settings;
}
}
6 changes: 3 additions & 3 deletions src/test/java/com/exactpro/th2/RecoveryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void testSequenceResetAdminMessages() {
ByteBuf resendRequest = Unpooled.wrappedBuffer("8=FIXT.1.1\u00019=73\u000135=2\u000134=2\u000149=client\u000156=server\u000150=trader\u000152=2014-12-22T10:15:30Z\u00017=1\u000116=5\u000110=226\u0001".getBytes(StandardCharsets.UTF_8));
fixHandler.onIncoming(channel, resendRequest, MessageID.getDefaultInstance());

// sequence reset for meesages from 1 to 3 ( 1, 2 - missing, 3 - admin )
// sequence reset for messages from 1 to 3 ( 1, 2 - missing, 3 - admin )
ByteBuf seqReset1 = channel.getQueue().get(1);
assertEquals(findField(seqReset1, MSG_TYPE_TAG).getValue(), MSG_TYPE_SEQUENCE_RESET);
assertEquals(Integer.parseInt(findField(seqReset1, MSG_SEQ_NUM_TAG).getValue()), 1);
Expand All @@ -215,7 +215,7 @@ void testSequenceResetAdminMessages() {
assertEquals(Integer.parseInt(findField(message, MSG_SEQ_NUM_TAG).getValue()), 4);
assertEquals(findField(message, POSS_DUP_TAG).getValue(), "Y");

// sequence reset for meesages from 1 to 3 ( 1, 2 - missing, 3 - admin )
// sequence reset for messages from 1 to 3 ( 1, 2 - missing, 3 - admin )
ByteBuf seqReset2 = channel.getQueue().get(3);
assertEquals(findField(seqReset2, MSG_TYPE_TAG).getValue(), MSG_TYPE_SEQUENCE_RESET);
assertEquals(Integer.parseInt(findField(seqReset2, MSG_SEQ_NUM_TAG).getValue()), 5);
Expand Down Expand Up @@ -245,7 +245,7 @@ void allMessagesMissed() {
ByteBuf resendRequest = Unpooled.wrappedBuffer("8=FIXT.1.1\u00019=73\u000135=2\u000134=2\u000149=client\u000156=server\u000150=trader\u000152=2014-12-22T10:15:30Z\u00017=1\u000116=5\u000110=226\u0001".getBytes(StandardCharsets.UTF_8));
fixHandler.onIncoming(channel, resendRequest, MessageID.getDefaultInstance());

// sequence reset for meesages from 1 to 3 ( 1, 2 - missing, 3 - admin )
// sequence reset for messages from 1 to 3 ( 1, 2 - missing, 3 - admin )
ByteBuf seqReset = channel.getQueue().get(1);
assertEquals(findField(seqReset, MSG_TYPE_TAG).getValue(), MSG_TYPE_SEQUENCE_RESET);
assertEquals(Integer.parseInt(findField(seqReset, MSG_SEQ_NUM_TAG).getValue()), 1);
Expand Down

0 comments on commit 38c9298

Please sign in to comment.