|
7 | 7 | import org.slf4j.Logger; |
8 | 8 | import org.slf4j.LoggerFactory; |
9 | 9 | import tech.ydb.common.transaction.TxMode; |
| 10 | +import tech.ydb.core.Result; |
10 | 11 | import tech.ydb.core.grpc.GrpcTransport; |
11 | 12 | import tech.ydb.examples.SimpleExample; |
12 | 13 | import tech.ydb.query.QueryClient; |
@@ -107,20 +108,19 @@ private void tableAndTopicWithinTransaction(TopicClient topicClient, QueryClient |
107 | 108 | // flush to wait until the message will reach the server before committing transaction |
108 | 109 | writer.flush(); |
109 | 110 |
|
110 | | - return transaction.commit() |
111 | | - .thenApply(commitResult -> { |
112 | | - try { |
113 | | - writer.shutdown(SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS); |
114 | | - } catch (TimeoutException exception) { |
115 | | - throw new RuntimeException("Shutdown not finished within " + SHUTDOWN_TIMEOUT_SECONDS + |
116 | | - " seconds"); |
117 | | - } catch (InterruptedException | ExecutionException exception) { |
118 | | - throw new RuntimeException("Shutdown not finished due to exception: " + exception); |
119 | | - } |
120 | | - // Return commit status to SessionRetryContext function |
121 | | - return commitResult.getStatus(); |
122 | | - }); |
123 | | - }).join().expectSuccess("Can't create table series"); |
| 111 | + // Shutdown writer |
| 112 | + try { |
| 113 | + writer.shutdown(SHUTDOWN_TIMEOUT_SECONDS, TimeUnit.SECONDS); |
| 114 | + } catch (TimeoutException exception) { |
| 115 | + throw new RuntimeException("Shutdown not finished within " + SHUTDOWN_TIMEOUT_SECONDS + |
| 116 | + " seconds"); |
| 117 | + } catch (InterruptedException | ExecutionException exception) { |
| 118 | + throw new RuntimeException("Shutdown not finished due to exception: " + exception); |
| 119 | + } |
| 120 | + |
| 121 | + // Return commit status to SessionRetryContext function |
| 122 | + return transaction.commit().thenApply(Result::getStatus); |
| 123 | + }).join().expectSuccess("Couldn't read from table and write to topic in transaction"); |
124 | 124 | } |
125 | 125 |
|
126 | 126 | public static void main(String[] args) { |
|
0 commit comments