test: add regression test for topic message retry
package com.hedera.hashgraph.sdk;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.assertThatThrownBy;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Queue;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java8.util.function.Consumer;
-
import com.google.common.base.Stopwatch;
import com.google.common.primitives.Longs;
import com.google.common.util.concurrent.Uninterruptibles;
@@ -30,6 +18,7 @@ import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.inprocess.InProcessServerBuilder;
import io.grpc.stub.StreamObserver;
+import java8.util.function.Consumer;
import org.apache.commons.lang3.ArrayUtils;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.AfterClass;
@@ -37,13 +26,23 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.threeten.bp.Duration;
import org.threeten.bp.Instant;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
class TopicMessageQueryTest {
private static final Instant START_TIME = Instant.now();
@@ -233,14 +232,19 @@ class TopicMessageQueryTest {
})
@Timeout(3)
void retryRecovers(Status.Code code, String description) {
- consensusServiceStub.requests.add(request().build());
- consensusServiceStub.requests.add(request().build());
+ ConsensusTopicResponse response = response(1L);
+ Instant nextTimestamp = toInstant(response.getConsensusTimestamp()).plusNanos(1L);
+ ConsensusTopicQuery.Builder request = request();
+
+ consensusServiceStub.requests.add(request.build());
+ consensusServiceStub.requests.add(request.setConsensusStartTime(toTimestamp(nextTimestamp)).build());
+ consensusServiceStub.responses.add(response);
consensusServiceStub.responses.add(code.toStatus().withDescription(description).asRuntimeException());
- consensusServiceStub.responses.add(response(1L));
+ consensusServiceStub.responses.add(response(2L));
subscribeToMirror(received::add);
- assertThat(received).hasSize(1).extracting(t -> t.sequenceNumber).containsExactly(1L);
+ assertThat(received).hasSize(2).extracting(t -> t.sequenceNumber).containsExactly(1L, 2L);
assertThat(errors).isEmpty();
}
