You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by da...@apache.org on 2017/01/06 19:59:04 UTC

[2/4] kudu git commit: KUDU-734. Add test coverage for encodings and strings

KUDU-734. Add test coverage for encodings and strings

Added a testAllPrimaryKeyTypes test to TestKeyEncoding class.
It covers the case of setting/getting all of the available primary key types.

Change-Id: Ia3fbeb0f889a4c454a48d11a6e42c7da0e58a329
Reviewed-on: http://gerrit.cloudera.org:8080/5588
Tested-by: Kudu Jenkins
Reviewed-by: Todd Lipcon <to...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/5bb5cdbe
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/5bb5cdbe
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/5bb5cdbe

Branch: refs/heads/master
Commit: 5bb5cdbe8544af4b670b5b4aa456b49f2f14762c
Parents: f3e6af7
Author: Jun He <ju...@gmail.com>
Authored: Sat Dec 31 22:09:39 2016 -0800
Committer: Todd Lipcon <to...@apache.org>
Committed: Thu Jan 5 21:16:49 2017 +0000

----------------------------------------------------------------------
 .../org/apache/kudu/client/TestKeyEncoding.java | 68 +++++++++++++++++++-
 1 file changed, 67 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/5bb5cdbe/java/kudu-client/src/test/java/org/apache/kudu/client/TestKeyEncoding.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKeyEncoding.java b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKeyEncoding.java
index f2415b1..0ae3479 100644
--- a/java/kudu-client/src/test/java/org/apache/kudu/client/TestKeyEncoding.java
+++ b/java/kudu-client/src/test/java/org/apache/kudu/client/TestKeyEncoding.java
@@ -34,7 +34,7 @@ import org.apache.kudu.Type;
 import org.apache.kudu.client.PartitionSchema.HashBucketSchema;
 import org.apache.kudu.client.PartitionSchema.RangeSchema;
 
-public class TestKeyEncoding {
+public class TestKeyEncoding extends BaseKuduTest {
 
   private static Schema buildSchema(ColumnSchemaBuilder... columns) {
     int i = 0;
@@ -78,6 +78,21 @@ public class TestKeyEncoding {
         ImmutableList.<PartitionSchema.HashBucketSchema>of(), schema);
   }
 
+  /**
+   * Builds the default CreateTableOptions for a schema.
+   *
+   * @param schema the schema
+   * @return a default CreateTableOptions
+   */
+  private CreateTableOptions defaultCreateTableOptions(Schema schema) {
+    List<String> columnNames = new ArrayList<>();
+    for (ColumnSchema columnSchema : schema.getPrimaryKeyColumns()) {
+      columnNames.add(columnSchema.getName());
+    }
+    return new CreateTableOptions()
+        .setRangePartitionColumns(columnNames);
+  }
+
   @Test
   public void testPrimaryKeys() {
     Schema schemaOneString =
@@ -299,4 +314,55 @@ public class TestKeyEncoding {
                           'c'                   // b = "c"
                       });
   }
+
+  @Test(timeout = 100000)
+  public void testAllPrimaryKeyTypes() throws Exception {
+    Schema schema = buildSchema(
+        new ColumnSchemaBuilder("int8", Type.INT8).key(true),
+        new ColumnSchemaBuilder("int16", Type.INT16).key(true),
+        new ColumnSchemaBuilder("int32", Type.INT32).key(true),
+        new ColumnSchemaBuilder("int64", Type.INT64).key(true),
+        new ColumnSchemaBuilder("string", Type.STRING).key(true),
+        new ColumnSchemaBuilder("binary", Type.BINARY).key(true),
+        new ColumnSchemaBuilder("timestamp", Type.UNIXTIME_MICROS).key(true),
+        new ColumnSchemaBuilder("bool", Type.BOOL),       // not primary key type
+        new ColumnSchemaBuilder("float", Type.FLOAT),     // not primary key type
+        new ColumnSchemaBuilder("double", Type.DOUBLE));  // not primary key type
+
+    KuduTable table = createTable("testAllPrimaryKeyTypes-" + System.currentTimeMillis(),
+        schema, defaultCreateTableOptions(schema));
+    KuduSession session = syncClient.newSession();
+
+    Insert insert = table.newInsert();
+    PartialRow row = insert.getRow();
+    row.addByte(0, (byte) 1);
+    row.addShort(1, (short) 2);
+    row.addInt(2, 3);
+    row.addLong(3, 4l);
+    row.addString(4, "foo");
+    row.addBinary(5, "bar".getBytes(Charsets.UTF_8));
+    row.addLong(6, 6l);
+    row.addBoolean(7, true);
+    row.addFloat(8, 8.8f);
+    row.addDouble(9, 9.9);
+    session.apply(insert);
+    session.close();
+
+    KuduScanner scanner = syncClient.newScannerBuilder(table).build();
+    while (scanner.hasMoreRows()) {
+      RowResultIterator it = scanner.nextRows();
+      assertTrue(it.hasNext());
+      RowResult rr = it.next();
+      assertEquals((byte) 0x01, rr.getByte(0));
+      assertEquals((short) 2, rr.getShort(1));
+      assertEquals(3, rr.getInt(2));
+      assertEquals(4l, rr.getLong(3));
+      assertBytesEquals(rr.getBinaryCopy(4), "foo");
+      assertBytesEquals(rr.getBinaryCopy(5), "bar");
+      assertEquals(6l, rr.getLong(6));
+      assertTrue(rr.getBoolean(7));
+      assertEquals(8.8f, rr.getFloat(8), .001f);
+      assertEquals(9.9, rr.getDouble(9), .001);
+    }
+  }
 }