Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.2k
Update BigTable conformance tests (#5901)#6166
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
Merged
BenWhitehead
merged 4 commits into
googleapis:master
from
BenWhitehead:bigtable-conformance-tests-updateAug 26, 2019
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
191 changes: 64 additions & 127 deletions
191 ...t/java/com/google/cloud/bigtable/data/v2/stub/readrows/ReadRowsMergingAcceptanceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -16,24 +16,25 @@ | ||
| package com.google.cloud.bigtable.data.v2.stub.readrows; | ||
| import static com.google.common.truth.Truth.assertThat; | ||
| import static com.google.common.truth.Truth.assertWithMessage; | ||
| import com.google.api.gax.rpc.ServerStream; | ||
| import com.google.api.gax.rpc.ServerStreamingCallable; | ||
| import com.google.bigtable.v2.ReadRowsRequest; | ||
| import com.google.bigtable.v2.ReadRowsResponse; | ||
| import com.google.bigtable.v2.ReadRowsResponse.CellChunk; | ||
| import com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter; | ||
| import com.google.cloud.bigtable.data.v2.models.Row; | ||
| import com.google.cloud.bigtable.data.v2.models.RowCell; | ||
| import com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable; | ||
| import com.google.cloud.conformance.bigtable.v2.TestDefinition.ReadRowsTest; | ||
| import com.google.cloud.conformance.bigtable.v2.TestDefinition.TestFile; | ||
| import com.google.common.base.CaseFormat; | ||
| import com.google.common.base.Objects; | ||
| import com.google.common.collect.Lists; | ||
| import com.google.gson.Gson; | ||
| import com.google.gson.annotations.SerializedName; | ||
| import com.google.protobuf.TextFormat; | ||
| import com.google.protobuf.util.JsonFormat; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.InputStreamReader; | ||
| import java.io.StringReader; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.List; | ||
| @@ -45,28 +46,43 @@ | ||
| /** Parses and runs the acceptance tests for read rows */ | ||
| @RunWith(Parameterized.class) | ||
| public class ReadRowsMergingAcceptanceTest { | ||
| private final ChunkTestCase testCase; | ||
| public ReadRowsMergingAcceptanceTest(ChunkTestCase testCase) { | ||
| this.testCase = testCase; | ||
| private static final String TEST_DATA_JSON_RESOURCE = | ||
| "com/google/cloud/conformance/bigtable/v2/readrows.json"; | ||
| private final ReadRowsTest testCase; | ||
| /** | ||
| * @param testData The serialized test data representing the test case. | ||
| * @param junitName Not used by the test, but used by the parameterized test runner as the name of | ||
| * the test. | ||
| */ | ||
| public ReadRowsMergingAcceptanceTest( | ||
| ReadRowsTest testData, @SuppressWarnings("unused") String junitName) { | ||
| this.testCase = testData; | ||
| } | ||
| @Parameters(name = "{0}") | ||
| public static Collection<Object[]> data() { | ||
| InputStream testInputStream = | ||
| ReadRowsMergingAcceptanceTest.class.getResourceAsStream("read-rows-acceptance-test.json"); | ||
| // Parse the json | ||
| Gson gson = new Gson(); | ||
| AcceptanceTest acceptanceTest = | ||
| gson.fromJson(new InputStreamReader(testInputStream), AcceptanceTest.class); | ||
| // Construct parameters for each test run | ||
| List<Object[]> data = new ArrayList<>(); | ||
| for (ChunkTestCase test : acceptanceTest.tests) { | ||
| data.add(new Object[] {test}); | ||
| // Each tuple consists of [testData: ReadRowsTest, junitName: String] | ||
| @Parameters(name = "{1}") | ||
BenWhitehead marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| public static Collection<Object[]> data() throws IOException { | ||
| ClassLoader cl = Thread.currentThread().getContextClassLoader(); | ||
| InputStream dataJson = cl.getResourceAsStream(TEST_DATA_JSON_RESOURCE); | ||
| assertWithMessage("Unable to load test definition: %s", TEST_DATA_JSON_RESOURCE) | ||
| .that(dataJson) | ||
| .isNotNull(); | ||
| InputStreamReader reader = new InputStreamReader(dataJson); | ||
| TestFile.Builder testBuilder = TestFile.newBuilder(); | ||
| JsonFormat.parser().merge(reader, testBuilder); | ||
| TestFile testDefinition = testBuilder.build(); | ||
| List<ReadRowsTest> tests = testDefinition.getReadRowsTestsList(); | ||
| ArrayList<Object[]> data = new ArrayList<>(tests.size()); | ||
| for (ReadRowsTest test : tests) { | ||
| String junitName = | ||
| CaseFormat.LOWER_HYPHEN.to( | ||
| CaseFormat.LOWER_CAMEL, test.getDescription().replace(" ", "-")); | ||
| data.add(new Object[] {test, junitName}); | ||
| } | ||
| return data; | ||
| } | ||
| @@ -75,9 +91,9 @@ public void test() throws Exception { | ||
| List<ReadRowsResponse> responses = Lists.newArrayList(); | ||
| // Convert the chunks into a single ReadRowsResponse | ||
| for (String chunkStr : testCase.chunks) { | ||
| for (CellChunk chunk : testCase.getChunksList()) { | ||
| ReadRowsResponse.Builder responseBuilder = ReadRowsResponse.newBuilder(); | ||
| TextFormat.merge(new StringReader(chunkStr), responseBuilder.addChunksBuilder()); | ||
| responseBuilder.addChunks(chunk); | ||
| responses.add(responseBuilder.build()); | ||
| } | ||
| @@ -91,134 +107,55 @@ public void test() throws Exception { | ||
| ServerStream<Row> stream = mergingCallable.call(ReadRowsRequest.getDefaultInstance()); | ||
| // Read all of the rows and transform them into logical cells | ||
| List<TestResult> actualResults = Lists.newArrayList(); | ||
| List<ReadRowsTest.Result> actualResults = Lists.newArrayList(); | ||
| Exception error = null; | ||
| try { | ||
| for (Row row : stream) { | ||
| for (RowCell cell : row.getCells()) { | ||
| actualResults.add( | ||
| new TestResult( | ||
| row.getKey().toStringUtf8(), | ||
| cell.getFamily(), | ||
| cell.getQualifier().toStringUtf8(), | ||
| cell.getTimestamp(), | ||
| cell.getValue().toStringUtf8(), | ||
| cell.getLabels().isEmpty() ? "" : cell.getLabels().get(0))); | ||
| ReadRowsTest.Result.newBuilder() | ||
| .setRowKeyBytes(row.getKey()) | ||
| .setFamilyName(cell.getFamily()) | ||
| .setQualifierBytes(cell.getQualifier()) | ||
| .setTimestampMicros(cell.getTimestamp()) | ||
| .setValueBytes(cell.getValue()) | ||
| .setLabel(cell.getLabels().isEmpty() ? "" : cell.getLabels().get(0)) | ||
| .build()); | ||
| } | ||
| } | ||
| } catch (Exception e) { | ||
| error = e; | ||
| } | ||
| // Verify the results | ||
| if (testCase.expectsError()) { | ||
| if (expectsError(testCase)) { | ||
| assertThat(error).isNotNull(); | ||
| } else { | ||
| if (error != null) { | ||
| throw error; | ||
| } | ||
| } | ||
| assertThat(testCase.getNonExceptionResults()).isEqualTo(actualResults); | ||
| assertThat(getNonExceptionResults(testCase)).isEqualTo(actualResults); | ||
| } | ||
| // <editor-fold desc="JSON data model populated by gson"> | ||
| private static final class AcceptanceTest { | ||
| List<ChunkTestCase> tests; | ||
| private static boolean expectsError(ReadRowsTest rrt) { | ||
| List<ReadRowsTest.Result> results = rrt.getResultsList(); | ||
| return results != null && !results.isEmpty() && results.get(results.size() - 1).getError(); | ||
| } | ||
| private static final class ChunkTestCase { | ||
| String name; | ||
| List<String> chunks; | ||
| List<TestResult> results; | ||
| /** The test name in the source file is an arbitrary string. Make it junit-friendly. */ | ||
| String getJunitTestName() { | ||
| return CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, name.replace(" ", "-")); | ||
| } | ||
| @Override | ||
| public String toString() { | ||
| return getJunitTestName(); | ||
| } | ||
| boolean expectsError() { | ||
| return results != null && !results.isEmpty() && results.get(results.size() - 1).error; | ||
| } | ||
| private static List<ReadRowsTest.Result> getNonExceptionResults(ReadRowsTest rrt) { | ||
| List<ReadRowsTest.Result> results = rrt.getResultsList(); | ||
| List<TestResult> getNonExceptionResults() { | ||
| ArrayList<TestResult> response = new ArrayList<>(); | ||
| if (results != null) { | ||
| for (TestResult result : results) { | ||
| if (!result.error) { | ||
| response.add(result); | ||
| } | ||
| List<ReadRowsTest.Result> response = new ArrayList<>(); | ||
| if (results != null) { | ||
| for (ReadRowsTest.Result result : results) { | ||
| if (!result.getError()) { | ||
| response.add(result); | ||
| } | ||
| } | ||
| return response; | ||
| } | ||
| } | ||
| private static final class TestResult { | ||
| @SerializedName("rk") | ||
| String rowKey; | ||
| @SerializedName("fm") | ||
| String family; | ||
| @SerializedName("qual") | ||
| String qualifier; | ||
| @SerializedName("ts") | ||
| long timestamp; | ||
| String value; | ||
| String label; | ||
| boolean error; | ||
| /** Constructor for JSon deserialization. */ | ||
| @SuppressWarnings("unused") | ||
| public TestResult() {} | ||
| TestResult( | ||
| String rowKey, | ||
| String family, | ||
| String qualifier, | ||
| long timestamp, | ||
| String value, | ||
| String label) { | ||
| this.rowKey = rowKey; | ||
| this.family = family; | ||
| this.qualifier = qualifier; | ||
| this.timestamp = timestamp; | ||
| this.value = value; | ||
| this.label = label; | ||
| this.error = false; | ||
| } | ||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| TestResult that = (TestResult) o; | ||
| return Objects.equal(rowKey, that.rowKey) | ||
| && Objects.equal(family, that.family) | ||
| && Objects.equal(qualifier, that.qualifier) | ||
| && timestamp == that.timestamp | ||
| && Objects.equal(value, that.value) | ||
| && Objects.equal(label, that.label) | ||
| && error == that.error; | ||
| } | ||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hashCode(rowKey, family, qualifier, timestamp, value, label, error); | ||
| } | ||
| return response; | ||
| } | ||
| // </editor-fold> | ||
| } | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.