Adapt stream Java tests to client 0.12.0 snapshot
After changes for https://github.com/rabbitmq/rabbitmq-stream-java-client/issues/333.
This commit is contained in:
parent
8b6d109968
commit
c594c77049
|
|
@ -26,7 +26,7 @@
|
||||||
</developers>
|
</developers>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<stream-client.version>0.11.0</stream-client.version>
|
<stream-client.version>[0.12.0-SNAPSHOT,)</stream-client.version>
|
||||||
<junit.jupiter.version>5.9.3</junit.jupiter.version>
|
<junit.jupiter.version>5.9.3</junit.jupiter.version>
|
||||||
<assertj.version>3.24.2</assertj.version>
|
<assertj.version>3.24.2</assertj.version>
|
||||||
<logback.version>1.2.12</logback.version>
|
<logback.version>1.2.12</logback.version>
|
||||||
|
|
@ -115,4 +115,15 @@
|
||||||
|
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>ossrh</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
<snapshots><enabled>true</enabled></snapshots>
|
||||||
|
<releases><enabled>false</enabled></releases>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
</repositories>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,8 @@
|
||||||
|
|
||||||
package com.rabbitmq.stream;
|
package com.rabbitmq.stream;
|
||||||
|
|
||||||
|
import static com.rabbitmq.stream.TestUtils.*;
|
||||||
import static com.rabbitmq.stream.TestUtils.ResponseConditions.ok;
|
import static com.rabbitmq.stream.TestUtils.ResponseConditions.ok;
|
||||||
import static com.rabbitmq.stream.TestUtils.waitAtMost;
|
|
||||||
import static com.rabbitmq.stream.TestUtils.waitUntil;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.fail;
|
import static org.assertj.core.api.Assertions.fail;
|
||||||
|
|
||||||
|
|
@ -164,7 +163,7 @@ public class FailureTest {
|
||||||
new Client.ClientParameters()
|
new Client.ClientParameters()
|
||||||
.port(TestUtils.streamPortNode1())
|
.port(TestUtils.streamPortNode1())
|
||||||
.messageListener(
|
.messageListener(
|
||||||
(subscriptionId, offset, chunkTimestamp, committedChunkId, msg) -> {
|
(subscriptionId, offset, chunkTimestamp, committedChunkId, context, msg) -> {
|
||||||
bodies.add(new String(msg.getBodyAsBinary(), StandardCharsets.UTF_8));
|
bodies.add(new String(msg.getBodyAsBinary(), StandardCharsets.UTF_8));
|
||||||
consumeLatch.countDown();
|
consumeLatch.countDown();
|
||||||
}));
|
}));
|
||||||
|
|
@ -341,11 +340,14 @@ public class FailureTest {
|
||||||
cf.get(
|
cf.get(
|
||||||
new Client.ClientParameters()
|
new Client.ClientParameters()
|
||||||
.port(m.getReplicas().get(0).getPort())
|
.port(m.getReplicas().get(0).getPort())
|
||||||
.chunkListener(
|
.chunkListener(credit())
|
||||||
(client1, subscriptionId, offset, messageCount, dataSize) ->
|
|
||||||
client1.credit(subscriptionId, 1))
|
|
||||||
.messageListener(
|
.messageListener(
|
||||||
(subscriptionId, offset, chunkTimestamp, committedChunkId, message) -> {
|
(subscriptionId,
|
||||||
|
offset,
|
||||||
|
chunkTimestamp,
|
||||||
|
committedChunkId,
|
||||||
|
context,
|
||||||
|
message) -> {
|
||||||
consumed.add(message);
|
consumed.add(message);
|
||||||
generations.add((Long) message.getApplicationProperties().get("generation"));
|
generations.add((Long) message.getApplicationProperties().get("generation"));
|
||||||
if (consumed.size() == confirmed.size()) {
|
if (consumed.size() == confirmed.size()) {
|
||||||
|
|
@ -447,7 +449,7 @@ public class FailureTest {
|
||||||
Set<Long> generations = ConcurrentHashMap.newKeySet();
|
Set<Long> generations = ConcurrentHashMap.newKeySet();
|
||||||
Set<Long> consumedIds = ConcurrentHashMap.newKeySet();
|
Set<Long> consumedIds = ConcurrentHashMap.newKeySet();
|
||||||
Client.MessageListener messageListener =
|
Client.MessageListener messageListener =
|
||||||
(subscriptionId, offset, chunkTimestamp, committedChunkId, message) -> {
|
(subscriptionId, offset, chunkTimestamp, committedChunkId, context, message) -> {
|
||||||
consumed.add(message);
|
consumed.add(message);
|
||||||
generations.add((Long) message.getApplicationProperties().get("generation"));
|
generations.add((Long) message.getApplicationProperties().get("generation"));
|
||||||
consumedIds.add(message.getProperties().getMessageIdAsLong());
|
consumedIds.add(message.getProperties().getMessageIdAsLong());
|
||||||
|
|
@ -471,9 +473,7 @@ public class FailureTest {
|
||||||
new Client.ClientParameters()
|
new Client.ClientParameters()
|
||||||
.port(newReplicaPort)
|
.port(newReplicaPort)
|
||||||
.shutdownListener(shutdownListenerReference.get())
|
.shutdownListener(shutdownListenerReference.get())
|
||||||
.chunkListener(
|
.chunkListener(credit())
|
||||||
(client1, subscriptionId, offset, messageCount, dataSize) ->
|
|
||||||
client1.credit(subscriptionId, 1))
|
|
||||||
.messageListener(messageListener));
|
.messageListener(messageListener));
|
||||||
|
|
||||||
newConsumer.subscribe(
|
newConsumer.subscribe(
|
||||||
|
|
@ -494,9 +494,7 @@ public class FailureTest {
|
||||||
new Client.ClientParameters()
|
new Client.ClientParameters()
|
||||||
.port(replica.getPort())
|
.port(replica.getPort())
|
||||||
.shutdownListener(shutdownListener)
|
.shutdownListener(shutdownListener)
|
||||||
.chunkListener(
|
.chunkListener(credit())
|
||||||
(client1, subscriptionId, offset, messageCount, dataSize) ->
|
|
||||||
client1.credit(subscriptionId, 1))
|
|
||||||
.messageListener(messageListener));
|
.messageListener(messageListener));
|
||||||
|
|
||||||
Client.Response response =
|
Client.Response response =
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package com.rabbitmq.stream;
|
package com.rabbitmq.stream;
|
||||||
|
|
||||||
|
import static com.rabbitmq.stream.TestUtils.credit;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import com.rabbitmq.stream.impl.Client;
|
import com.rabbitmq.stream.impl.Client;
|
||||||
|
|
@ -115,11 +116,14 @@ public class StreamTest {
|
||||||
cf.get(
|
cf.get(
|
||||||
new Client.ClientParameters()
|
new Client.ClientParameters()
|
||||||
.port(consumerBroker.apply(streamMetadata).getPort())
|
.port(consumerBroker.apply(streamMetadata).getPort())
|
||||||
.chunkListener(
|
.chunkListener(credit())
|
||||||
(client1, subscriptionId, offset, messageCount1, dataSize) ->
|
|
||||||
client1.credit(subscriptionId, 10))
|
|
||||||
.messageListener(
|
.messageListener(
|
||||||
(subscriptionId, offset, chunkTimestamp, committedChunkId, message) -> {
|
(subscriptionId,
|
||||||
|
offset,
|
||||||
|
chunkTimestamp,
|
||||||
|
committedChunkId,
|
||||||
|
context,
|
||||||
|
message) -> {
|
||||||
bodies.add(new String(message.getBodyAsBinary(), StandardCharsets.UTF_8));
|
bodies.add(new String(message.getBodyAsBinary(), StandardCharsets.UTF_8));
|
||||||
consumingLatch.countDown();
|
consumingLatch.countDown();
|
||||||
}));
|
}));
|
||||||
|
|
@ -128,7 +132,8 @@ public class StreamTest {
|
||||||
|
|
||||||
assertThat(consumingLatch.await(10, TimeUnit.SECONDS)).isTrue();
|
assertThat(consumingLatch.await(10, TimeUnit.SECONDS)).isTrue();
|
||||||
assertThat(bodies).hasSize(messageCount);
|
assertThat(bodies).hasSize(messageCount);
|
||||||
IntStream.range(0, messageCount).forEach(i -> assertThat(bodies.contains("hello " + i)));
|
IntStream.range(0, messageCount)
|
||||||
|
.forEach(i -> assertThat(bodies.contains("hello " + i)).isTrue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -218,4 +218,11 @@ public class TestUtils {
|
||||||
expectedResponse);
|
expectedResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Client.ChunkListener credit() {
|
||||||
|
return (client, subscriptionId, offset, messageCount, dataSize) -> {
|
||||||
|
client.credit(subscriptionId, 1);
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
</developers>
|
</developers>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<stream-client.version>0.11.0</stream-client.version>
|
<stream-client.version>[0.12.0-SNAPSHOT,)</stream-client.version>
|
||||||
<junit.jupiter.version>5.9.3</junit.jupiter.version>
|
<junit.jupiter.version>5.9.3</junit.jupiter.version>
|
||||||
<assertj.version>3.24.2</assertj.version>
|
<assertj.version>3.24.2</assertj.version>
|
||||||
<logback.version>1.2.12</logback.version>
|
<logback.version>1.2.12</logback.version>
|
||||||
|
|
@ -131,4 +131,15 @@
|
||||||
|
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
|
||||||
|
<repository>
|
||||||
|
<id>ossrh</id>
|
||||||
|
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
|
||||||
|
<snapshots><enabled>true</enabled></snapshots>
|
||||||
|
<releases><enabled>false</enabled></releases>
|
||||||
|
</repository>
|
||||||
|
|
||||||
|
</repositories>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
||||||
|
|
@ -140,11 +140,6 @@ public class HttpTest {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<Map<String, Object>> entities(
|
|
||||||
List<Map<String, Object>> entities, Predicate<Map<String, Object>> filter) {
|
|
||||||
return entities.stream().filter(filter).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
static Map<String, Object> entity(
|
static Map<String, Object> entity(
|
||||||
List<Map<String, Object>> entities, Predicate<Map<String, Object>> filter) {
|
List<Map<String, Object>> entities, Predicate<Map<String, Object>> filter) {
|
||||||
return entities.stream().filter(filter).findFirst().orElse(Collections.emptyMap());
|
return entities.stream().filter(filter).findFirst().orElse(Collections.emptyMap());
|
||||||
|
|
@ -558,9 +553,7 @@ public class HttpTest {
|
||||||
cf.get(
|
cf.get(
|
||||||
new ClientParameters()
|
new ClientParameters()
|
||||||
.clientProperty("connection_name", connectionProvidedName)
|
.clientProperty("connection_name", connectionProvidedName)
|
||||||
.chunkListener(
|
.chunkListener(TestUtils.credit())
|
||||||
(client1, subscriptionId, offset, messageCount, dataSize) ->
|
|
||||||
client1.credit(subscriptionId, 1))
|
|
||||||
.shutdownListener(shutdownContext -> closed.set(true)));
|
.shutdownListener(shutdownContext -> closed.set(true)));
|
||||||
|
|
||||||
client.subscribe((byte) 0, stream, OffsetSpecification.first(), 10, subscriptionProperties);
|
client.subscribe((byte) 0, stream, OffsetSpecification.first(), 10, subscriptionProperties);
|
||||||
|
|
|
||||||
|
|
@ -257,4 +257,11 @@ public class TestUtils {
|
||||||
static Condition<Object> isNull() {
|
static Condition<Object> isNull() {
|
||||||
return new Condition<>(Objects::isNull, "null");
|
return new Condition<>(Objects::isNull, "null");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Client.ChunkListener credit() {
|
||||||
|
return (client, subscriptionId, offset, messageCount, dataSize) -> {
|
||||||
|
client.credit(subscriptionId, 1);
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue