Skip to content

Commit

Permalink
Merge pull request #48 from AngusDavis/integration_test_round_1
Browse files Browse the repository at this point in the history
Get a few integration tests passing
  • Loading branch information
AngusDavis committed Sep 13, 2014
2 parents 8eb1e55 + 077dd26 commit e011bb7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
32 changes: 22 additions & 10 deletions src/main/java/com/google/cloud/anviltop/hbase/AnvilTopTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,19 @@ public HTableDescriptor getTableDescriptor() throws IOException {

@Override
public boolean exists(Get get) throws IOException {
throw new UnsupportedOperationException(); // TODO
// TODO: make use of strip_value() or count to hopefully return no extra data
Result result = get(get);
return !result.isEmpty();
}

@Override
public Boolean[] exists(List<Get> gets) throws IOException {
throw new UnsupportedOperationException(); // TODO
Boolean[] results = new Boolean[gets.size()];
for (int i = 0; i < gets.size(); i++) {
Get get = gets.get(i);
results[i] = exists(get);
}
return results;
}

@Override
Expand Down Expand Up @@ -165,7 +172,12 @@ public Result get(Get get) throws IOException {

@Override
public Result[] get(List<Get> gets) throws IOException {
throw new UnsupportedOperationException(); // TODO
Result[] results = new Result[gets.size()];
for (int i = 0; i < gets.size(); i++) {
Get get = gets.get(i);
results[i] = get(get);
}
return results;
}

@Override
Expand Down Expand Up @@ -208,7 +220,9 @@ public void put(Put put) throws IOException {

@Override
public void put(List<Put> puts) throws IOException {
throw new UnsupportedOperationException(); // TODO
for (Put put : puts) {
put(put);
}
}

@Override
Expand Down Expand Up @@ -243,7 +257,9 @@ public void delete(Delete delete) throws IOException {

@Override
public void delete(List<Delete> deletes) throws IOException {
throw new UnsupportedOperationException(); // TODO
for (Delete delete : deletes) {
delete(delete);
}
}

@Override
Expand Down Expand Up @@ -300,7 +316,7 @@ public long incrementColumnValue(byte[] row, byte[] family, byte[] qualifier, lo

@Override
public boolean isAutoFlush() {
throw new UnsupportedOperationException(); // TODO
return true;
}

@Override
Expand All @@ -310,7 +326,6 @@ public void flushCommits() throws IOException {

@Override
public void close() throws IOException {
throw new UnsupportedOperationException(); // TODO
}

@Override
Expand All @@ -333,17 +348,14 @@ public <T extends Service, R> void coprocessorService(Class<T> service, byte[] s

@Override
public void setAutoFlush(boolean autoFlush) {
throw new UnsupportedOperationException(); // TODO
}

@Override
public void setAutoFlush(boolean autoFlush, boolean clearBufferOnFail) {
throw new UnsupportedOperationException(); // TODO
}

@Override
public void setAutoFlushTo(boolean autoFlush) {
throw new UnsupportedOperationException(); // TODO
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ScanAdapter
implements OperationAdapter<Scan, AnviltopData.ReadOptions.Builder> {

private final static byte[] NULL_CHARACTER_BYTES = Bytes.toBytes("\\x00");
public static final String ALL_QUALIFIERS = "\\\\C*";
public static final String ALL_QUALIFIERS = "\\C*";
public static final String ALL_FAMILIES = ".*";
public static final String ALL_VERSIONS = "ALL";
public static final char INTERLEAVE_CHARACTER = '+';
Expand Down Expand Up @@ -101,10 +101,11 @@ static void writeScanStream(
scan.getMaxVersions() == Integer.MAX_VALUE ?
ALL_VERSIONS : Integer.toString(scan.getMaxVersions());

outputStream.write(Bytes.toBytes("col("));
outputStream.write(Bytes.toBytes("col({"));
outputStream.write(family);
outputStream.write(':');
outputStream.write(qualifier);
outputStream.write('}');
outputStream.write(',');
outputStream.write(' ');
outputStream.write(Bytes.toBytes(versionPart));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void filterIsPopulatedInGetRequests() throws ServiceException, IOExceptio
Mockito.when(mockClient.getRow(Mockito.any(AnviltopServices.GetRowRequest.class)))
.thenReturn(AnviltopServices.GetRowResponse.getDefaultInstance());

String expectedFilter = "(col(family:qualifier, 1))";
String expectedFilter = "(col({family:qualifier}, 1))";
table.get(
new Get(Bytes.toBytes("rowKey1"))
.addColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private void putGetDeleteExists(byte[] rowKey, byte[] testQualifier, byte[] test

// Delete
Delete delete = new Delete(rowKey);
delete.deleteColumn(COLUMN_FAMILY, testQualifier);
delete.deleteColumns(COLUMN_FAMILY, testQualifier);
table.delete(delete);

// Confirm deleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void testGetWithSingleColumnFamily() throws IOException {

GetRowRequest.Builder rowRequestBuilder = getAdapter.adapt(get);

Assert.assertEquals("(col(family1:\\\\C*, ALL))", rowRequestBuilder.getFilter());
Assert.assertEquals("(col({family1:\\C*}, ALL))", rowRequestBuilder.getFilter());
}

@Test
Expand All @@ -77,7 +77,7 @@ public void testGetWithMultipleColumnFamily() throws IOException {

GetRowRequest.Builder rowRequestBuilder = getAdapter.adapt(get);

Assert.assertEquals("(col(family1:\\\\C*, ALL))+(col(family2:\\\\C*, ALL))",
Assert.assertEquals("(col({family1:\\C*}, ALL))+(col({family2:\\C*}, ALL))",
rowRequestBuilder.getFilter());
}

Expand All @@ -94,8 +94,8 @@ public void testTimestampLimitsAreApplied() throws IOException {
GetRowRequest.Builder rowRequestBuilder = getAdapter.adapt(get);

Assert.assertEquals(
"(col(family1:\\\\C*, ALL) | ts(1000000, 1999000))" +
"+(col(family2:\\\\C*, ALL) | ts(1000000, 1999000))",
"(col({family1:\\C*}, ALL) | ts(1000000, 1999000))" +
"+(col({family2:\\C*}, ALL) | ts(1000000, 1999000))",
rowRequestBuilder.getFilter());
}

Expand All @@ -111,7 +111,7 @@ public void testMaxVersionsIsApplied() throws IOException {
GetRowRequest.Builder rowRequestBuilder = getAdapter.adapt(get);

Assert.assertEquals(
"(col(family1:\\\\C*, 1))+(col(family2:\\\\C*, 1))",
"(col({family1:\\C*}, 1))+(col({family2:\\C*}, 1))",
rowRequestBuilder.getFilter());
}

Expand All @@ -125,7 +125,7 @@ public void testMultipleFamiliesSomeWithQualifiersSpecified() throws IOException
GetRowRequest.Builder rowRequestBuilder = getAdapter.adapt(get);

Assert.assertEquals(
"(col(family1:\\\\C*, 1))+(col(family2:qualifier1, 1))",
"(col({family1:\\C*}, 1))+(col({family2:qualifier1}, 1))",
rowRequestBuilder.getFilter());
}

Expand All @@ -146,13 +146,13 @@ public void testBinaryColumnNamesAreQuoted() throws IOException {
GetRowRequest.Builder rowRequestBuilder = getAdapter.adapt(get);

ByteArrayOutputStream expectedFilterBuilder = new ByteArrayOutputStream();
expectedFilterBuilder.write(Bytes.toBytes("(col(f1:"));
expectedFilterBuilder.write(Bytes.toBytes("(col({f1:"));
expectedFilterBuilder.write(Bytes.toBytes(utf8Part)); // Only ASCII characters need escaping
expectedFilterBuilder.write(Bytes.toBytes(asciiPart)); // Leave a-z intact
expectedFilterBuilder.write(Bytes.toBytes("\\x00")); // null byte
expectedFilterBuilder.write(
Bytes.toBytes("\\\\\\[\\]\\(\\)\\.\\*")); // Escape each in special characters
expectedFilterBuilder.write(Bytes.toBytes(", ALL))"));
expectedFilterBuilder.write(Bytes.toBytes("}, ALL))"));
Assert.assertArrayEquals(
expectedFilterBuilder.toByteArray(),
rowRequestBuilder.getFilterBytes().toByteArray());
Expand Down

0 comments on commit e011bb7

Please sign in to comment.