From ba038a6d8c83098dc3ad26e50a1d9c38f109c288 Mon Sep 17 00:00:00 2001 From: StrongestNumber9 <16169054+StrongestNumber9@users.noreply.github.com> Date: Mon, 21 Aug 2023 15:42:32 +0300 Subject: [PATCH 1/7] Reindent and untabify pom.xml, no functional changes --- pom.xml | 157 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 78 insertions(+), 79 deletions(-) diff --git a/pom.xml b/pom.xml index 251870a..18bc28e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,71 +1,70 @@ - jar - 4.0.0 - rlp_01 - rlp_01 - A minimal RELP implementation. - https://teragrep.com - com.teragrep - ${revision}${sha1}${changelist} - - UTF-8 - UTF-8 - 0.0.1 - -SNAPSHOT - - 1.8 - 1.8 - 1.8 - 5.9.3 - - - - - Apache License v2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - - - - - - Mikko Kortelainen - 1@teragrep.com - Teragrep - https://teragrep.com - - - - - scm:git:https://github.com/teragrep/rlp_01.git - scm:git:git@github.com:teragrep/rlp_01.git - https://github.com/teragrep/rlp_01/tree/master - - - - - - - com.teragrep - tls_01 - 0.7.1 - - - org.junit.jupiter - junit-jupiter-api - test - ${junit.version} - - - org.junit.vintage - junit-vintage-engine - test - ${junit.version} - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + jar + 4.0.0 + rlp_01 + rlp_01 + A minimal RELP implementation. + https://teragrep.com + com.teragrep + ${revision}${sha1}${changelist} + + UTF-8 + UTF-8 + 0.0.1 + -SNAPSHOT + + 1.8 + 1.8 + 1.8 + 5.9.3 + + + + + Apache License v2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + + + + + + Mikko Kortelainen + 1@teragrep.com + Teragrep + https://teragrep.com + + + + + scm:git:https://github.com/teragrep/rlp_01.git + scm:git:git@github.com:teragrep/rlp_01.git + https://github.com/teragrep/rlp_01/tree/master + + + + + + com.teragrep + tls_01 + 0.7.1 + + + org.junit.jupiter + junit-jupiter-api + test + ${junit.version} + + + org.junit.vintage + junit-vintage-engine + test + ${junit.version} + - + ${project.basedir}/target rlp_01 @@ -100,13 +99,13 @@ - org.apache.maven.plugins - maven-surefire-plugin + org.apache.maven.plugins + maven-surefire-plugin 2.22.2 - - all - true - + + all + true + org.apache.maven.plugins @@ -122,12 +121,12 @@ - org.apache.maven.plugins - maven-deploy-plugin - 2.8.2 - - false - + org.apache.maven.plugins + maven-deploy-plugin + 2.8.2 + + false + org.codehaus.mojo @@ -158,7 +157,7 @@ - publish-maven-central + publish-maven-central @@ -196,7 +195,7 @@ - publish-github-packages + publish-github-packages From 266edbb7ab7b0f8f7505d933c9a85e35c65b5309 Mon Sep 17 00:00:00 2001 From: StrongestNumber9 <16169054+StrongestNumber9@users.noreply.github.com> Date: Mon, 21 Aug 2023 15:47:05 +0300 Subject: [PATCH 2/7] Adds explicit compiler, maven-enforce-plugins, update all the other built in plugin versions --- pom.xml | 51 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 18bc28e..03eca08 100644 --- a/pom.xml +++ b/pom.xml @@ -69,10 +69,47 @@ ${project.basedir}/target rlp_01 + + maven-compiler-plugin + 3.11.0 + + -Xlint:all + + + + maven-enforcer-plugin + 3.3.0 + + + enforce + none + + + enforce-maven + + enforce + + + + + 3.2.5 + + + + + + + + + 1.8 + + + + org.apache.maven.plugins maven-source-plugin - 2.2.1 + 3.2.1 attach-sources @@ -85,7 +122,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.9.1 + 3.4.1 attach-javadocs @@ -101,7 +138,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.22.2 + 3.0.0-M7 all true @@ -110,7 +147,7 @@ org.apache.maven.plugins maven-failsafe-plugin - 3.0.0-M5 + 3.1.2 @@ -123,7 +160,7 @@ org.apache.maven.plugins maven-deploy-plugin - 2.8.2 + 3.0.0 false @@ -131,7 +168,7 @@ org.codehaus.mojo flatten-maven-plugin - 1.1.0 + 1.3.0 true resolveCiFriendliesOnly @@ -163,7 +200,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.6 + 3.0.1 sign-artifacts From f3766510fb8f0fc6e961a6f63df7a363f587945a Mon Sep 17 00:00:00 2001 From: StrongestNumber9 <16169054+StrongestNumber9@users.noreply.github.com> Date: Mon, 21 Aug 2023 16:15:47 +0300 Subject: [PATCH 3/7] Modernize existing test, remove unnecessary one --- pom.xml | 5 +- .../com/teragrep/rlp_01/SendMessageTest.java | 96 ------------------- .../java/com/teragrep/rlp_01/UnitTest.java | 60 ++++++------ 3 files changed, 31 insertions(+), 130 deletions(-) delete mode 100644 src/test/java/com/teragrep/rlp_01/SendMessageTest.java diff --git a/pom.xml b/pom.xml index 03eca08..19cb89e 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,8 @@ 1.8 1.8 1.8 - 5.9.3 + 5.10.0 + 0.7.1 @@ -49,7 +50,7 @@ com.teragrep tls_01 - 0.7.1 + ${teragrep.tls_01.version} org.junit.jupiter diff --git a/src/test/java/com/teragrep/rlp_01/SendMessageTest.java b/src/test/java/com/teragrep/rlp_01/SendMessageTest.java deleted file mode 100644 index 078ae56..0000000 --- a/src/test/java/com/teragrep/rlp_01/SendMessageTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - Java Reliable Event Logging Protocol Library RLP-01 - Copyright (C) 2021, 2022 Suomen Kanuuna Oy - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -package com.teragrep.rlp_01; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.util.concurrent.TimeoutException; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class SendMessageTest { - /* - private String hostname; - private int port; - - @Before - public void init() throws IOException, InterruptedException { - this.hostname = "localhost"; - this.port = 1235; - } - - @After - public void cleanup() throws IOException { - } - - @Test - public void testSendBatch() throws IllegalStateException, IOException, TimeoutException { - RelpConnection relpSession = new RelpConnection(); - relpSession.connect(this.hostname, this.port); - String msg = "<14>1 2020-05-15T13:24:03.603Z CFE-16 capsulated - - [CFE-16-metadata@48577 authentication_token=\"AUTH_TOKEN_11111\" channel=\"CHANNEL_11111\" time_source=\"generated\"][CFE-16-origin@48577] \"Hello, world!\"\n"; - byte[] data = msg.getBytes("UTF-8"); - int n = 200; - RelpBatch batch = new RelpBatch(); - for (int i = 0; i < n; i++) { - batch.insert(data); - } - relpSession.commit(batch); - assertTrue(batch.verifyTransactionAll()); - relpSession.disconnect(); - } - - @Test - public void testSendMessage() throws IOException, TimeoutException { - RelpConnection relpSession = new RelpConnection(); - relpSession.connect(this.hostname, this.port); - String msg = "<14>1 2020-05-15T13:24:03.603Z CFE-16 capsulated - - [CFE-16-metadata@48577 authentication_token=\"AUTH_TOKEN_11111\" channel=\"CHANNEL_11111\" time_source=\"generated\"][CFE-16-origin@48577] \"Hello, world!\"\n"; - byte[] data = msg.getBytes("UTF-8"); - RelpBatch batch = new RelpBatch(); - long reqId = batch.insert(data); - relpSession.commit(batch); - // verify successful transaction - assertTrue(batch.verifyTransaction(reqId)); - relpSession.disconnect(); - } - - @Test - public void testOpenAndCloseSession() throws IOException, TimeoutException { - RelpConnection relpSession = new RelpConnection(); - relpSession.connect(this.hostname, this.port); - relpSession.disconnect(); - } - - @Test - public void testSessionCloseTwice() throws IOException, TimeoutException { - RelpConnection relpSession = new RelpConnection(); - relpSession.connect(this.hostname, this.port); - relpSession.disconnect(); - try { - relpSession.disconnect(); - fail("IllegalStateException should have been thrown."); - } catch (IllegalStateException e) { - // this is expected - } - } - */ -} diff --git a/src/test/java/com/teragrep/rlp_01/UnitTest.java b/src/test/java/com/teragrep/rlp_01/UnitTest.java index f55e577..024c19a 100644 --- a/src/test/java/com/teragrep/rlp_01/UnitTest.java +++ b/src/test/java/com/teragrep/rlp_01/UnitTest.java @@ -19,87 +19,83 @@ import static org.junit.jupiter.api.Assertions.assertEquals; -import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; public class UnitTest { - @Rule - public ExpectedException exceptionRule = ExpectedException.none(); - @Test - public void testCode200() throws UnsupportedEncodingException { + public void testCode200() { String message = "200 OK"; int len = message.length(); ByteBuffer buffer = ByteBuffer.allocateDirect(len); - buffer.put(message.getBytes("UTF-8")); + buffer.put(message.getBytes(StandardCharsets.UTF_8)); buffer.flip(); RelpFrameRX frame = new RelpFrameRX(2, RelpCommand.SYSLOG, len, buffer); assertEquals(frame.getResponseCode(), 200); } @Test - public void testCode500() throws UnsupportedEncodingException { + public void testCode500() { String message = "500 NOK"; int len = message.length(); ByteBuffer buffer = ByteBuffer.allocateDirect(len); - buffer.put(message.getBytes("UTF-8")); + buffer.put(message.getBytes(StandardCharsets.UTF_8)); buffer.flip(); RelpFrameRX frame = new RelpFrameRX(2, RelpCommand.SYSLOG, len, buffer); assertEquals(frame.getResponseCode(), 500); } @Test - public void testCode123() throws UnsupportedEncodingException { + public void testCode123() { String message = "123 OK"; int len = message.length(); ByteBuffer buffer = ByteBuffer.allocateDirect(len); - buffer.put(message.getBytes("UTF-8")); + buffer.put(message.getBytes(StandardCharsets.UTF_8)); buffer.flip(); RelpFrameRX frame = new RelpFrameRX(2, RelpCommand.SYSLOG, len, buffer); assertEquals(frame.getResponseCode(), 123); } @Test - public void testCodeEmpty() throws UnsupportedEncodingException { + public void testCodeEmpty() { String message = ""; - int len = message.length(); + int len = 0; ByteBuffer buffer = ByteBuffer.allocateDirect(len); - buffer.put(message.getBytes("UTF-8")); + buffer.put(message.getBytes(StandardCharsets.UTF_8)); buffer.flip(); - RelpFrameRX frame = new RelpFrameRX(2, RelpCommand.SYSLOG, len, buffer); - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("response code not present"); - frame.getResponseCode(); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + RelpFrameRX frame = new RelpFrameRX(2, RelpCommand.SYSLOG, len, buffer); + frame.getResponseCode(); + }); } @Test - public void testCodeNoCode() throws UnsupportedEncodingException { + public void testCodeNoCode() { String message = " "; int len = message.length(); ByteBuffer buffer = ByteBuffer.allocateDirect(len); - buffer.put(message.getBytes("UTF-8")); + buffer.put(message.getBytes(StandardCharsets.UTF_8)); buffer.flip(); - RelpFrameRX frame = new RelpFrameRX(2, RelpCommand.SYSLOG, len, buffer); - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("response code not a number"); - frame.getResponseCode(); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + RelpFrameRX frame = new RelpFrameRX(2, RelpCommand.SYSLOG, len, buffer); + frame.getResponseCode(); + }); } @Test - public void testCode2000() throws UnsupportedEncodingException { + public void testCode2000() { String message = "2000 OK"; int len = message.length(); ByteBuffer buffer = ByteBuffer.allocateDirect(len); - buffer.put(message.getBytes("UTF-8")); + buffer.put(message.getBytes(StandardCharsets.UTF_8)); buffer.flip(); - RelpFrameRX frame = new RelpFrameRX(2, RelpCommand.SYSLOG, len, buffer); - exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage("response code too long"); - frame.getResponseCode(); + Assertions.assertThrows(IllegalArgumentException.class, () -> { + RelpFrameRX frame = new RelpFrameRX(2, RelpCommand.SYSLOG, len, buffer); + frame.getResponseCode(); + }); } } From f718591e570c9c015d9968470e58c4edeba531ae Mon Sep 17 00:00:00 2001 From: StrongestNumber9 <16169054+StrongestNumber9@users.noreply.github.com> Date: Mon, 21 Aug 2023 17:18:29 +0300 Subject: [PATCH 4/7] Adds Batch, Window and RequestID tests --- .../rlp_01/{UnitTest.java => CodeTest.java} | 10 +- .../com/teragrep/rlp_01/RelpBatchTest.java | 178 ++++++++++++++++++ .../com/teragrep/rlp_01/RelpWindowTest.java | 56 ++++++ .../com/teragrep/rlp_01/RequestIDTest.java | 30 +++ 4 files changed, 268 insertions(+), 6 deletions(-) rename src/test/java/com/teragrep/rlp_01/{UnitTest.java => CodeTest.java} (91%) create mode 100644 src/test/java/com/teragrep/rlp_01/RelpBatchTest.java create mode 100644 src/test/java/com/teragrep/rlp_01/RelpWindowTest.java create mode 100644 src/test/java/com/teragrep/rlp_01/RequestIDTest.java diff --git a/src/test/java/com/teragrep/rlp_01/UnitTest.java b/src/test/java/com/teragrep/rlp_01/CodeTest.java similarity index 91% rename from src/test/java/com/teragrep/rlp_01/UnitTest.java rename to src/test/java/com/teragrep/rlp_01/CodeTest.java index 024c19a..7a306ce 100644 --- a/src/test/java/com/teragrep/rlp_01/UnitTest.java +++ b/src/test/java/com/teragrep/rlp_01/CodeTest.java @@ -17,15 +17,13 @@ package com.teragrep.rlp_01; -import static org.junit.jupiter.api.Assertions.assertEquals; - import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -public class UnitTest { +public class CodeTest { @Test public void testCode200() { @@ -35,7 +33,7 @@ public void testCode200() { buffer.put(message.getBytes(StandardCharsets.UTF_8)); buffer.flip(); RelpFrameRX frame = new RelpFrameRX(2, RelpCommand.SYSLOG, len, buffer); - assertEquals(frame.getResponseCode(), 200); + Assertions.assertEquals(200, frame.getResponseCode(), "Got wrong response code"); } @Test @@ -46,7 +44,7 @@ public void testCode500() { buffer.put(message.getBytes(StandardCharsets.UTF_8)); buffer.flip(); RelpFrameRX frame = new RelpFrameRX(2, RelpCommand.SYSLOG, len, buffer); - assertEquals(frame.getResponseCode(), 500); + Assertions.assertEquals(500, frame.getResponseCode(), "Got wrong response code"); } @Test @@ -57,7 +55,7 @@ public void testCode123() { buffer.put(message.getBytes(StandardCharsets.UTF_8)); buffer.flip(); RelpFrameRX frame = new RelpFrameRX(2, RelpCommand.SYSLOG, len, buffer); - assertEquals(frame.getResponseCode(), 123); + Assertions.assertEquals(123, frame.getResponseCode(), "Got wrong response code"); } @Test diff --git a/src/test/java/com/teragrep/rlp_01/RelpBatchTest.java b/src/test/java/com/teragrep/rlp_01/RelpBatchTest.java new file mode 100644 index 0000000..cd31e25 --- /dev/null +++ b/src/test/java/com/teragrep/rlp_01/RelpBatchTest.java @@ -0,0 +1,178 @@ +/* + Java Reliable Event Logging Protocol Library RLP-01 + Copyright (C) 2021, 2022 Suomen Kanuuna Oy + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + + +package com.teragrep.rlp_01; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; + +public class RelpBatchTest { + private static final String message = "syslog message"; + + @Test + public void testInsert() { + RelpBatch batch = new RelpBatch(); + Long id = batch.insert(message.getBytes(StandardCharsets.UTF_8)); + RelpFrameTX frame = batch.getRequest(id); + Assertions.assertEquals( + String.format( + "0 syslog %s %s", + message.length(), + message + ), + frame.toString(), + "Did not receive expected value from getRequest" + ); + } + + @Test + public void testGetNullRequest() { + RelpBatch batch = new RelpBatch(); + RelpFrameTX frame = batch.getRequest(1L); + Assertions.assertNull(frame, "Frame was not null"); + } + + @Test + public void testRemoveRequest() { + RelpBatch batch = new RelpBatch(); + Long id = batch.insert(message.getBytes(StandardCharsets.UTF_8)); + Assertions.assertNotNull(batch.getRequest(id), "Request was null"); + batch.removeRequest(id); + Assertions.assertNull(batch.getRequest(id), "Request was not removed"); + } + + @Test + public void testRemoveNullRequest() { + RelpBatch batch = new RelpBatch(); + Assertions.assertDoesNotThrow(() -> {batch.removeRequest(1234L);}); + } + + @Test + public void testGetNullResponse() { + RelpBatch batch = new RelpBatch(); + Long id = batch.insert(message.getBytes(StandardCharsets.UTF_8)); + RelpFrameRX frame = batch.getResponse(id); + Assertions.assertNull(frame, "Got invalid response"); + } + + @Test + public void testGetResponse() { + RelpBatch batch = new RelpBatch(); + Long id = batch.insert(message.getBytes(StandardCharsets.UTF_8)); + Assertions.assertNull(batch.getResponse(id), "Got a response but shouldn't have"); + batch.putResponse(id, new RelpFrameRX(id.intValue(), "X", 1, ByteBuffer.allocateDirect(1))); + Assertions.assertNotNull(batch.getResponse(id), "Got a null response"); + } + + @Test + public void testRemoveTransaction() { + RelpBatch batch = new RelpBatch(); + Long id = batch.insert(message.getBytes(StandardCharsets.UTF_8)); + Assertions.assertFalse(batch.verifyTransactionAll(), "Verified transaction"); + batch.removeTransaction(id); + Assertions.assertTrue(batch.verifyTransactionAll(), "Didn't verify transaction"); + } + + @Test + public void testVerifyTransaction() { + RelpBatch batch = new RelpBatch(); + Long id = batch.insert(message.getBytes(StandardCharsets.UTF_8)); + Assertions.assertFalse(batch.verifyTransaction(id), "Verified transaction"); + String response = "200 OK"; + ByteBuffer buffer = ByteBuffer.allocateDirect(response.length()); + buffer.put(response.getBytes(StandardCharsets.UTF_8)); + buffer.flip(); + batch.putResponse(id, new RelpFrameRX(id.intValue(), RelpCommand.SYSLOG, response.length(), buffer)); + Assertions.assertTrue(batch.verifyTransactionAll(), "Didn't verify transaction"); + } + + @Test + public void testVerifyTransactionAll() { + RelpBatch batch = new RelpBatch(); + int messages = 5; + Long[] ids = new Long[messages]; + for(int i=0; i Date: Mon, 21 Aug 2023 17:23:24 +0300 Subject: [PATCH 5/7] Fixes wrong command in verifyTransaction test --- src/test/java/com/teragrep/rlp_01/RelpBatchTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/teragrep/rlp_01/RelpBatchTest.java b/src/test/java/com/teragrep/rlp_01/RelpBatchTest.java index cd31e25..9138aad 100644 --- a/src/test/java/com/teragrep/rlp_01/RelpBatchTest.java +++ b/src/test/java/com/teragrep/rlp_01/RelpBatchTest.java @@ -102,7 +102,7 @@ public void testVerifyTransaction() { buffer.put(response.getBytes(StandardCharsets.UTF_8)); buffer.flip(); batch.putResponse(id, new RelpFrameRX(id.intValue(), RelpCommand.SYSLOG, response.length(), buffer)); - Assertions.assertTrue(batch.verifyTransactionAll(), "Didn't verify transaction"); + Assertions.assertTrue(batch.verifyTransaction(id), "Didn't verify transaction"); } @Test From 62861a2a252dc314f1316621927b408e0b1a40b5 Mon Sep 17 00:00:00 2001 From: StrongestNumber9 <16169054+StrongestNumber9@users.noreply.github.com> Date: Mon, 21 Aug 2023 17:28:12 +0300 Subject: [PATCH 6/7] Adds test multiple pending, fixes removePending test, makes size test a bit more strict --- .../com/teragrep/rlp_01/RelpWindowTest.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/teragrep/rlp_01/RelpWindowTest.java b/src/test/java/com/teragrep/rlp_01/RelpWindowTest.java index 6b13bb3..1c50b29 100644 --- a/src/test/java/com/teragrep/rlp_01/RelpWindowTest.java +++ b/src/test/java/com/teragrep/rlp_01/RelpWindowTest.java @@ -28,6 +28,16 @@ public void testGetPending() { Assertions.assertEquals(1, window.size(), "Window size is wrong"); } + @Test + public void testGetMultiplePending() { + RelpWindow window = new RelpWindow(); + window.putPending(12, 1234L); + window.putPending(13, 555L); + Assertions.assertEquals(1234, window.getPending(12), "Got wrong requestId value"); + Assertions.assertEquals(555, window.getPending(13), "Got wrong requestId value"); + Assertions.assertEquals(2, window.size(), "Window size is wrong"); + } + @Test public void testIsPending() { RelpWindow window = new RelpWindow(); @@ -39,8 +49,9 @@ public void testIsPending() { public void testRemovePending() { RelpWindow window = new RelpWindow(); window.putPending(12, 1234L); + Assertions.assertTrue(window.isPending(12), "Transaction id is not pending"); window.removePending(12); - Assertions.assertFalse(window.isPending(1234), "Transaction id is pending"); + Assertions.assertFalse(window.isPending(12), "Transaction id is pending"); } @Test @@ -52,5 +63,9 @@ public void testPendingSize() { window.putPending(i, (long) i); } Assertions.assertEquals(messages, window.size(), "Unexpected amount of events in window"); + for(int i=1; i<=messages; i++) { + window.removePending(i); + } + Assertions.assertEquals(0, window.size(), "Unexpected amount of events in window"); } } From 9ecc6505fffd431b6339ce22a68f51797a9f5881 Mon Sep 17 00:00:00 2001 From: StrongestNumber9 <16169054+StrongestNumber9@users.noreply.github.com> Date: Tue, 22 Aug 2023 09:15:12 +0300 Subject: [PATCH 7/7] Fixes requested changes --- src/test/java/com/teragrep/rlp_01/RelpBatchTest.java | 5 ++--- src/test/java/com/teragrep/rlp_01/RelpWindowTest.java | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/teragrep/rlp_01/RelpBatchTest.java b/src/test/java/com/teragrep/rlp_01/RelpBatchTest.java index 9138aad..9dd3638 100644 --- a/src/test/java/com/teragrep/rlp_01/RelpBatchTest.java +++ b/src/test/java/com/teragrep/rlp_01/RelpBatchTest.java @@ -47,7 +47,7 @@ public void testInsert() { @Test public void testGetNullRequest() { RelpBatch batch = new RelpBatch(); - RelpFrameTX frame = batch.getRequest(1L); + RelpFrameTX frame = batch.getRequest(0L); Assertions.assertNull(frame, "Frame was not null"); } @@ -126,8 +126,7 @@ public void testVerifyTransactionAll() { Assertions.assertTrue(batch.verifyTransactionAll(), "Did not verify all transactions"); } - // FIXME: getWorkQueueLength() should decrease as retrying failed ones? - @Disabled + // FIXME: https://github.com/teragrep/rlp_01/issues/12 @Test public void testRetryAllFailed() { RelpBatch batch = new RelpBatch(); diff --git a/src/test/java/com/teragrep/rlp_01/RelpWindowTest.java b/src/test/java/com/teragrep/rlp_01/RelpWindowTest.java index 1c50b29..e9ae550 100644 --- a/src/test/java/com/teragrep/rlp_01/RelpWindowTest.java +++ b/src/test/java/com/teragrep/rlp_01/RelpWindowTest.java @@ -59,8 +59,8 @@ public void testPendingSize() { RelpWindow window = new RelpWindow(); Assertions.assertEquals(0, window.size(), "Unexpected amount of events in window"); int messages = 5; - for(int i=1; i<=messages; i++) { - window.putPending(i, (long) i); + for(Long i=1L; i<=messages; i++) { + window.putPending(i.intValue(), i); } Assertions.assertEquals(messages, window.size(), "Unexpected amount of events in window"); for(int i=1; i<=messages; i++) {