Skip to content

Commit 53998f0

Browse files
committed
Topic tests adjustments
1 parent 9d761ba commit 53998f0

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<log4j.version>2.22.1</log4j.version>
1919
<jcommander.version>1.82</jcommander.version>
2020

21-
<ydb.sdk.version>2.2.0-SNAPSHOT</ydb.sdk.version>
21+
<ydb.sdk.version>2.2.0</ydb.sdk.version>
2222
</properties>
2323

2424
<modules>

ydb-cookbook/src/main/java/tech/ydb/examples/topic/ReadSync.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package tech.ydb.examples.topic;
22

3-
import java.io.IOException;
43
import java.nio.charset.StandardCharsets;
54
import java.time.Duration;
65
import java.time.Instant;
6+
import java.util.List;
77

88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
1010
import tech.ydb.core.grpc.GrpcTransport;
1111
import tech.ydb.examples.SimpleExample;
12-
import tech.ydb.table.Session;
1312
import tech.ydb.topic.TopicClient;
13+
import tech.ydb.topic.description.MetadataItem;
1414
import tech.ydb.topic.read.DecompressionException;
1515
import tech.ydb.topic.read.Message;
1616
import tech.ydb.topic.read.SyncReader;
@@ -31,7 +31,7 @@ protected void run(GrpcTransport transport, String pathPrefix) {
3131
ReaderSettings settings = ReaderSettings.newBuilder()
3232
.setConsumerName(CONSUMER_NAME)
3333
.addTopic(TopicReadSettings.newBuilder()
34-
.setPath(CONSUMER_NAME)
34+
.setPath(TOPIC_NAME)
3535
.setReadFrom(Instant.now().minus(Duration.ofHours(24)))
3636
.setMaxLag(Duration.ofMinutes(30))
3737
.build())
@@ -42,7 +42,6 @@ protected void run(GrpcTransport transport, String pathPrefix) {
4242
// Init in background
4343
reader.init();
4444

45-
4645
try {
4746
// Reading 5 messages
4847
for (int i = 0; i < 5; i++) {

ydb-cookbook/src/main/java/tech/ydb/examples/topic/transactions/TransactionWriteAsync.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ protected void run(GrpcTransport transport, String pathPrefix) {
9696
switch (result.getState()) {
9797
case WRITTEN:
9898
WriteAck.Details details = result.getDetails();
99-
logger.info("Message was written successfully."
100-
+ ", offset: " + details.getOffset());
99+
logger.info("Message was written successfully, offset: " +
100+
details.getOffset());
101101
break;
102102
case ALREADY_WRITTEN:
103103
logger.warn("Message was already written");
@@ -106,7 +106,9 @@ protected void run(GrpcTransport transport, String pathPrefix) {
106106
break;
107107
}
108108
}
109-
});
109+
})
110+
// Waiting for message to reach server before transaction commit
111+
.join();
110112
} catch (QueueOverflowException exception) {
111113
logger.error("Queue overflow exception while sending message{}: ", index, exception);
112114
// Send queue is full. Need retry with backoff or skip

ydb-cookbook/src/main/java/tech/ydb/examples/topic/transactions/TransactionWriteSync.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77

88
import org.slf4j.Logger;
99
import org.slf4j.LoggerFactory;
10-
import tech.ydb.common.transaction.BaseTransaction;
1110
import tech.ydb.common.transaction.TxMode;
1211
import tech.ydb.core.Result;
1312
import tech.ydb.core.grpc.GrpcTransport;
1413
import tech.ydb.examples.SimpleExample;
1514
import tech.ydb.table.Session;
1615
import tech.ydb.table.TableClient;
1716
import tech.ydb.table.transaction.TableTransaction;
18-
import tech.ydb.table.transaction.Transaction;
19-
import tech.ydb.table.transaction.TxControl;
2017
import tech.ydb.topic.TopicClient;
2118
import tech.ydb.topic.description.Codec;
2219
import tech.ydb.topic.settings.SendSettings;
@@ -92,11 +89,11 @@ protected void run(GrpcTransport transport, String pathPrefix) {
9289
} catch (InterruptedException | ExecutionException exception) {
9390
logger.error("Couldn't put message {} into sending queue due to exception: ", i, exception);
9491
}
92+
// flush to wait until all messages reach server before commit
93+
writer.flush();
9594
transaction.commit().join();
9695
}
9796

98-
writer.flush();
99-
logger.info("Flush finished");
10097
long shutdownTimeoutSeconds = 10;
10198
try {
10299
writer.shutdown(shutdownTimeoutSeconds, TimeUnit.SECONDS);

0 commit comments

Comments
 (0)