Search in sources :

Example 6 with TableSchema

use of com.nearinfinity.honeycomb.mysql.schema.TableSchema in project honeycomb by altamiracorp.

the class HBaseMetadataPropertyTest method testSchemaGet.

@Test
public void testSchemaGet() throws Exception {
    long tableId;
    for (String tableName : tableSchemas.keySet()) {
        TableSchema expected = tableSchemas.get(tableName);
        tableId = hbaseMetadata.getTableId(tableName);
        TableSchema actual = hbaseMetadata.getSchema(tableId);
        Assert.assertEquals(expected, actual);
    }
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) Test(org.junit.Test)

Example 7 with TableSchema

use of com.nearinfinity.honeycomb.mysql.schema.TableSchema in project honeycomb by altamiracorp.

the class HBaseMetadataPropertyTest method testSchemaDeleteRemovesTable.

@Test(expected = TableNotFoundException.class)
public void testSchemaDeleteRemovesTable() throws Exception {
    TableSchema schema = tableSchemaGen.next();
    final String tableName = TableSchemaGenerator.MYSQL_NAME_GEN.next();
    hbaseMetadata.createTable(tableName, schema);
    long tableId = hbaseMetadata.getTableId(tableName);
    Assert.assertEquals(schema, hbaseMetadata.getSchema(tableId));
    hbaseMetadata.deleteTable(tableName);
    hbaseMetadata.getSchema(tableId);
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) Test(org.junit.Test)

Example 8 with TableSchema

use of com.nearinfinity.honeycomb.mysql.schema.TableSchema in project honeycomb by altamiracorp.

the class HBaseMetadataTest method testCreateIndex.

@Test
public void testCreateIndex() {
    final TableSchema tableSchema = new TableSchema(COLUMN_SCHEMAS, ImmutableList.<IndexSchema>of());
    // Create a new table with the configured details
    hbaseMetadata.createTable(TABLE_NAME, tableSchema);
    final long tableId = hbaseMetadata.getTableId(TABLE_NAME);
    // Verify that the table schema has no indices after creation
    final TableSchema schemaBefore = hbaseMetadata.getSchema(tableId);
    assertNotNull(schemaBefore);
    assertTrue(schemaBefore.getIndices().isEmpty());
    // Add a new index to the table
    hbaseMetadata.createTableIndex(tableId, new IndexSchema(INDEX_NAME, ImmutableList.<String>of(COLUMN_NAME), false));
    // Verify that the table schema has been correctly updated
    final TableSchema schemaAfter = hbaseMetadata.getSchema(tableId);
    assertNotNull(schemaAfter);
    final Collection<IndexSchema> schemaIndices = schemaAfter.getIndices();
    assertEquals(1, schemaIndices.size());
    final IndexSchema newIndexDetails = Iterables.find(schemaIndices, indexPredicate);
    assertNotNull(newIndexDetails);
    final List<String> indexColumns = newIndexDetails.getColumns();
    assertEquals(1, indexColumns.size());
    assertEquals(COLUMN_NAME, indexColumns.get(0));
    assertEquals(false, newIndexDetails.getIsUnique());
    // Verify that the new index has been stored correctly
    final Map<String, Long> tableIndexInfo = hbaseMetadata.getIndexIds(tableId);
    assertEquals(1, tableIndexInfo.size());
    assertTrue(tableIndexInfo.containsKey(INDEX_NAME));
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) Test(org.junit.Test)

Example 9 with TableSchema

use of com.nearinfinity.honeycomb.mysql.schema.TableSchema in project honeycomb by altamiracorp.

the class HBaseMetadataTest method testLookupIndexIdsValidTableId.

@Test
public void testLookupIndexIdsValidTableId() {
    final TableSchema tableSchema = new TableSchema(COLUMN_SCHEMAS, ImmutableList.of(new IndexSchema(INDEX_NAME, Lists.newArrayList(COLUMN_NAME), false)));
    hbaseMetadata.createTable(TABLE_NAME, tableSchema);
    final long tableId = hbaseMetadata.getTableId(TABLE_NAME);
    final Map<String, Long> tableIndices = hbaseMetadata.getIndexIds(tableId);
    assertEquals(1, tableIndices.size());
    assertTrue(tableIndices.containsKey(INDEX_NAME));
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) Test(org.junit.Test)

Example 10 with TableSchema

use of com.nearinfinity.honeycomb.mysql.schema.TableSchema in project honeycomb by altamiracorp.

the class HBaseMetadataTest method testAutoInc.

@Test
public void testAutoInc() throws Exception {
    TableSchema table = TABLE_SCHEMA_GEN.next();
    final String tableName = TableSchemaGenerator.MYSQL_NAME_GEN.next();
    hbaseMetadata.createTable(tableName, table);
    long tableId = hbaseMetadata.getTableId(tableName);
    long value = LONG_GEN.next();
    assertEquals(hbaseMetadata.getAutoInc(tableId), 0);
    assertEquals(hbaseMetadata.incrementAutoInc(tableId, value), value);
    assertEquals(hbaseMetadata.getAutoInc(tableId), value);
    hbaseMetadata.setAutoInc(tableId, 13);
    assertEquals(hbaseMetadata.getAutoInc(tableId), 13);
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) Test(org.junit.Test)

Aggregations

TableSchema (com.nearinfinity.honeycomb.mysql.schema.TableSchema)34 Test (org.junit.Test)17 IndexSchema (com.nearinfinity.honeycomb.mysql.schema.IndexSchema)12 ColumnSchema (com.nearinfinity.honeycomb.mysql.schema.ColumnSchema)9 IndexRowKey (com.nearinfinity.honeycomb.hbase.rowkey.IndexRowKey)5 AvroTableSchema (com.nearinfinity.honeycomb.mysql.gen.AvroTableSchema)5 Predicate (com.google.common.base.Predicate)1 ImmutableList (com.google.common.collect.ImmutableList)1 UnsignedBytes (com.google.common.primitives.UnsignedBytes)1 MockHTable (com.nearinfinity.honeycomb.MockHTable)1 Scanner (com.nearinfinity.honeycomb.Scanner)1 Table (com.nearinfinity.honeycomb.Table)1 IndexRowKeyBuilder (com.nearinfinity.honeycomb.hbase.rowkey.IndexRowKeyBuilder)1 RowKey (com.nearinfinity.honeycomb.hbase.rowkey.RowKey)1 HandlerProxy (com.nearinfinity.honeycomb.mysql.HandlerProxy)1 Row (com.nearinfinity.honeycomb.mysql.Row)1 HoneycombIntegrationTest (integrationtests.HoneycombIntegrationTest)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1