@@ -85,7 +85,10 @@ public void tearDown() throws Exception {
8585 }
8686
8787 private StreamWriterV2 getTestStreamWriterV2 () throws IOException {
88- return StreamWriterV2 .newBuilder (TEST_STREAM , client ).setTraceId (TEST_TRACE_ID ).build ();
88+ return StreamWriterV2 .newBuilder (TEST_STREAM , client )
89+ .setWriterSchema (createProtoSchema ())
90+ .setTraceId (TEST_TRACE_ID )
91+ .build ();
8992 }
9093
9194 private ProtoSchema createProtoSchema () {
@@ -112,19 +115,6 @@ private ProtoRows createProtoRows(String[] messages) {
112115 return rowsBuilder .build ();
113116 }
114117
115- private AppendRowsRequest createAppendRequest (String [] messages , long offset ) {
116- AppendRowsRequest .Builder requestBuilder = AppendRowsRequest .newBuilder ();
117- AppendRowsRequest .ProtoData .Builder dataBuilder = AppendRowsRequest .ProtoData .newBuilder ();
118- dataBuilder .setWriterSchema (createProtoSchema ());
119- if (offset > 0 ) {
120- requestBuilder .setOffset (Int64Value .of (offset ));
121- }
122- return requestBuilder
123- .setProtoRows (dataBuilder .setRows (createProtoRows (messages )).build ())
124- .setWriteStream (TEST_STREAM )
125- .build ();
126- }
127-
128118 private AppendRowsResponse createAppendResponse (long offset ) {
129119 return AppendRowsResponse .newBuilder ()
130120 .setAppendResult (
@@ -139,7 +129,7 @@ private AppendRowsResponse createAppendResponseWithError(Status.Code code, Strin
139129 }
140130
141131 private ApiFuture <AppendRowsResponse > sendTestMessage (StreamWriterV2 writer , String [] messages ) {
142- return writer .append (createAppendRequest (messages , -1 ) );
132+ return writer .append (createProtoRows (messages ) , -1 );
143133 }
144134
145135 private static <T extends Throwable > T assertFutureException (
@@ -201,6 +191,7 @@ public void testBuildBigQueryWriteClientInWriter() throws Exception {
201191 StreamWriterV2 .newBuilder (TEST_STREAM )
202192 .setCredentialsProvider (NoCredentialsProvider .create ())
203193 .setChannelProvider (serviceHelper .createChannelProvider ())
194+ .setWriterSchema (createProtoSchema ())
204195 .build ();
205196
206197 testBigQueryWrite .addResponse (createAppendResponse (0 ));
@@ -210,12 +201,8 @@ public void testBuildBigQueryWriteClientInWriter() throws Exception {
210201 }
211202
212203 @ Test
213- public void testAppendWithRowsSuccess () throws Exception {
214- StreamWriterV2 writer =
215- StreamWriterV2 .newBuilder (TEST_STREAM , client )
216- .setWriterSchema (createProtoSchema ())
217- .setTraceId (TEST_TRACE_ID )
218- .build ();
204+ public void testAppendSuccess () throws Exception {
205+ StreamWriterV2 writer = getTestStreamWriterV2 ();
219206
220207 long appendCount = 100 ;
221208 for (int i = 0 ; i < appendCount ; i ++) {
@@ -237,38 +224,14 @@ public void testAppendWithRowsSuccess() throws Exception {
237224 }
238225
239226 @ Test
240- public void testAppendWithMessageSuccess () throws Exception {
241- StreamWriterV2 writer = getTestStreamWriterV2 ();
242-
243- long appendCount = 1000 ;
244- for (int i = 0 ; i < appendCount ; i ++) {
245- testBigQueryWrite .addResponse (createAppendResponse (i ));
246- }
247-
248- List <ApiFuture <AppendRowsResponse >> futures = new ArrayList <>();
249- for (int i = 0 ; i < appendCount ; i ++) {
250- futures .add (writer .append (createAppendRequest (new String [] {String .valueOf (i )}, i )));
251- }
252-
253- for (int i = 0 ; i < appendCount ; i ++) {
254- assertEquals (i , futures .get (i ).get ().getAppendResult ().getOffset ().getValue ());
255- }
256-
257- verifyAppendRequests (appendCount );
258-
259- writer .close ();
260- }
261-
262- @ Test
263- public void testAppendWithRowsNoSchema () throws Exception {
264- final StreamWriterV2 writer = getTestStreamWriterV2 ();
227+ public void testNoSchema () throws Exception {
265228 StatusRuntimeException ex =
266229 assertThrows (
267230 StatusRuntimeException .class ,
268231 new ThrowingRunnable () {
269232 @ Override
270233 public void run () throws Throwable {
271- writer . append ( createProtoRows ( new String [] { "A" }), - 1 );
234+ StreamWriterV2 . newBuilder ( TEST_STREAM , client ). build ( );
272235 }
273236 });
274237 assertEquals (ex .getStatus ().getCode (), Status .INVALID_ARGUMENT .getCode ());
@@ -455,7 +418,10 @@ public void serverCloseWhileRequestsInflight() throws Exception {
455418 @ Test
456419 public void testZeroMaxInflightRequests () throws Exception {
457420 StreamWriterV2 writer =
458- StreamWriterV2 .newBuilder (TEST_STREAM , client ).setMaxInflightRequests (0 ).build ();
421+ StreamWriterV2 .newBuilder (TEST_STREAM , client )
422+ .setWriterSchema (createProtoSchema ())
423+ .setMaxInflightRequests (0 )
424+ .build ();
459425 testBigQueryWrite .addResponse (createAppendResponse (0 ));
460426 verifyAppendIsBlocked (writer );
461427 writer .close ();
@@ -464,7 +430,10 @@ public void testZeroMaxInflightRequests() throws Exception {
464430 @ Test
465431 public void testZeroMaxInflightBytes () throws Exception {
466432 StreamWriterV2 writer =
467- StreamWriterV2 .newBuilder (TEST_STREAM , client ).setMaxInflightBytes (0 ).build ();
433+ StreamWriterV2 .newBuilder (TEST_STREAM , client )
434+ .setWriterSchema (createProtoSchema ())
435+ .setMaxInflightBytes (0 )
436+ .build ();
468437 testBigQueryWrite .addResponse (createAppendResponse (0 ));
469438 verifyAppendIsBlocked (writer );
470439 writer .close ();
@@ -473,7 +442,10 @@ public void testZeroMaxInflightBytes() throws Exception {
473442 @ Test
474443 public void testOneMaxInflightRequests () throws Exception {
475444 StreamWriterV2 writer =
476- StreamWriterV2 .newBuilder (TEST_STREAM , client ).setMaxInflightRequests (1 ).build ();
445+ StreamWriterV2 .newBuilder (TEST_STREAM , client )
446+ .setWriterSchema (createProtoSchema ())
447+ .setMaxInflightRequests (1 )
448+ .build ();
477449 // Server will sleep 1 second before every response.
478450 testBigQueryWrite .setResponseSleep (Duration .ofSeconds (1 ));
479451 testBigQueryWrite .addResponse (createAppendResponse (0 ));
@@ -489,7 +461,10 @@ public void testOneMaxInflightRequests() throws Exception {
489461 @ Test
490462 public void testAppendsWithTinyMaxInflightBytes () throws Exception {
491463 StreamWriterV2 writer =
492- StreamWriterV2 .newBuilder (TEST_STREAM , client ).setMaxInflightBytes (1 ).build ();
464+ StreamWriterV2 .newBuilder (TEST_STREAM , client )
465+ .setWriterSchema (createProtoSchema ())
466+ .setMaxInflightBytes (1 )
467+ .build ();
493468 // Server will sleep 100ms before every response.
494469 testBigQueryWrite .setResponseSleep (Duration .ofMillis (100 ));
495470 long appendCount = 10 ;
@@ -500,7 +475,7 @@ public void testAppendsWithTinyMaxInflightBytes() throws Exception {
500475 List <ApiFuture <AppendRowsResponse >> futures = new ArrayList <>();
501476 long appendStartTimeMs = System .currentTimeMillis ();
502477 for (int i = 0 ; i < appendCount ; i ++) {
503- futures .add (writer .append (createAppendRequest (new String [] {String .valueOf (i )}, i ) ));
478+ futures .add (writer .append (createProtoRows (new String [] {String .valueOf (i )}) , i ));
504479 }
505480 long appendElapsedMs = System .currentTimeMillis () - appendStartTimeMs ;
506481 assertTrue (appendElapsedMs >= 1000 );
0 commit comments