Skip to content

Commit

Permalink
feat: add default stream support for StreamWriter (#744)
Browse files Browse the repository at this point in the history
* fix: a race condition in test

* .

* .

* fix: allow default stream name to StreamWriter

* .
  • Loading branch information
yirutang committed Dec 17, 2020
1 parent 29f2bac commit 248ab73
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class StreamWriter implements AutoCloseable {
private static final Logger LOG = Logger.getLogger(StreamWriter.class.getName());

private static String streamPatternString =
"(projects/[^/]+/datasets/[^/]+/tables/[^/]+)/streams/[^/]+";
"(projects/[^/]+/datasets/[^/]+/tables/[^/]+)/(streams/[^/]+|_default)";

private static Pattern streamPattern = Pattern.compile(streamPatternString);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
public class StreamWriterTest {
private static final Logger LOG = Logger.getLogger(StreamWriterTest.class.getName());
private static final String TEST_STREAM = "projects/p/datasets/d/tables/t/streams/s";
private static final String TEST_DEFAULT_STREAM = "projects/p/datasets/d/tables/t/_default";
private static final ExecutorProvider SINGLE_THREAD_EXECUTOR =
InstantiatingExecutorProvider.newBuilder().setExecutorThreadCount(1).build();
private static LocalChannelProvider channelProvider;
Expand Down Expand Up @@ -102,6 +103,10 @@ private StreamWriter.Builder getTestStreamWriterBuilder() {
return getTestStreamWriterBuilder(TEST_STREAM);
}

private StreamWriter.Builder getDefaultTestStreamWriterBuilder() {
return getTestStreamWriterBuilder(TEST_DEFAULT_STREAM);
}

private AppendRowsRequest createAppendRequest(String[] messages, long offset) {
AppendRowsRequest.Builder requestBuilder = AppendRowsRequest.newBuilder();
AppendRowsRequest.ProtoData.Builder dataBuilder = AppendRowsRequest.ProtoData.newBuilder();
Expand Down Expand Up @@ -143,6 +148,13 @@ public void testTableName() throws Exception {
}
}

@Test
public void testDefaultStream() throws Exception {
try (StreamWriter writer = getDefaultTestStreamWriterBuilder().build()) {
assertEquals("projects/p/datasets/d/tables/t", writer.getTableNameString());
}
}

@Test
public void testAppendByDuration() throws Exception {
StreamWriter writer =
Expand Down

0 comments on commit 248ab73

Please sign in to comment.