Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: A test race in JsonStreamWriterTest #722

Merged
merged 3 commits into from Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -34,9 +34,7 @@
import com.google.protobuf.Descriptors.DescriptorValidationException;
import com.google.protobuf.Timestamp;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;
import org.json.JSONArray;
Expand Down Expand Up @@ -777,13 +775,13 @@ public void testMultiThreadAppendNoSchemaUpdate() throws Exception {
final JSONArray jsonArr = new JSONArray();
jsonArr.put(foo);

final HashSet<Long> offset_sets = new HashSet<Long>();
final Collection<Long> offsetSets = Collections.synchronizedCollection(new HashSet<Long>());
int thread_nums = 5;
Thread[] thread_arr = new Thread[thread_nums];
for (int i = 0; i < thread_nums; i++) {
testBigQueryWrite.addResponse(
Storage.AppendRowsResponse.newBuilder().setOffset((long) i).build());
offset_sets.add((long) i);
offsetSets.add((long) i);
Thread t =
new Thread(
new Runnable() {
Expand All @@ -792,7 +790,7 @@ public void run() {
ApiFuture<AppendRowsResponse> appendFuture =
writer.append(jsonArr, -1, /* allowUnknownFields */ false);
AppendRowsResponse response = appendFuture.get();
offset_sets.remove(response.getOffset());
offsetSets.remove(response.getOffset());
} catch (Exception e) {
LOG.severe("Thread execution failed: " + e.getMessage());
}
Expand All @@ -805,7 +803,7 @@ public void run() {
for (int i = 0; i < thread_nums; i++) {
thread_arr[i].join();
}
assertTrue(offset_sets.size() == 0);
assertTrue(offsetSets.size() == 0);
for (int i = 0; i < thread_nums; i++) {
assertEquals(
1,
Expand Down Expand Up @@ -842,7 +840,7 @@ public void testMultiThreadAppendWithSchemaUpdate() throws Exception {
final JSONArray jsonArr = new JSONArray();
jsonArr.put(foo);

final HashSet<Long> offsetSets = new HashSet<Long>();
final Collection<Long> offsetSets = Collections.synchronizedCollection(new HashSet<Long>());
int numberThreads = 5;
Thread[] thread_arr = new Thread[numberThreads];
for (int i = 0; i < numberThreads; i++) {
Expand Down
Expand Up @@ -33,9 +33,7 @@
import com.google.protobuf.Descriptors.DescriptorValidationException;
import com.google.protobuf.Timestamp;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;
import org.json.JSONArray;
Expand Down Expand Up @@ -775,12 +773,12 @@ public void testMultiThreadAppendNoSchemaUpdate() throws Exception {
final JSONArray jsonArr = new JSONArray();
jsonArr.put(foo);

final HashSet<Long> offset_sets = new HashSet<Long>();
final Collection<Long> offsetSets = Collections.synchronizedCollection(new HashSet<Long>());
int thread_nums = 5;
Thread[] thread_arr = new Thread[thread_nums];
for (int i = 0; i < thread_nums; i++) {
testBigQueryWrite.addResponse(AppendRowsResponse.newBuilder().setOffset((long) i).build());
offset_sets.add((long) i);
offsetSets.add((long) i);
Thread t =
new Thread(
new Runnable() {
Expand All @@ -789,7 +787,7 @@ public void run() {
ApiFuture<AppendRowsResponse> appendFuture =
writer.append(jsonArr, -1, /* allowUnknownFields */ false);
AppendRowsResponse response = appendFuture.get();
offset_sets.remove(response.getOffset());
offsetSets.remove(response.getOffset());
} catch (Exception e) {
LOG.severe("Thread execution failed: " + e.getMessage());
}
Expand All @@ -802,7 +800,7 @@ public void run() {
for (int i = 0; i < thread_nums; i++) {
thread_arr[i].join();
}
assertTrue(offset_sets.size() == 0);
assertTrue(offsetSets.size() == 0);
for (int i = 0; i < thread_nums; i++) {
assertEquals(
1,
Expand Down Expand Up @@ -839,7 +837,7 @@ public void testMultiThreadAppendWithSchemaUpdate() throws Exception {
final JSONArray jsonArr = new JSONArray();
jsonArr.put(foo);

final HashSet<Long> offsetSets = new HashSet<Long>();
final Collection<Long> offsetSets = Collections.synchronizedCollection(new HashSet<Long>());
int numberThreads = 5;
Thread[] thread_arr = new Thread[numberThreads];
for (int i = 0; i < numberThreads; i++) {
Expand Down