Search in sources :

Example 21 with ColumnSchema

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

the class HBaseMetadataTest method testRenameExistingTableNoAutoFlush.

@Test(expected = TableNotFoundException.class)
public void testRenameExistingTableNoAutoFlush() throws Exception {
    String originalName = "OriginalName";
    String newName = "NewName";
    TableSchema origSchema = TABLE_SCHEMA_GEN.next();
    // Configure the table to disable auto flush
    HTableInterface hTableSpy = PowerMockito.spy(MockHTable.create());
    Mockito.when(hTableSpy.isAutoFlush()).thenReturn(false);
    hbaseMetadata.createTable(originalName, origSchema);
    long origId = hbaseMetadata.getTableId(originalName);
    hbaseMetadata.renameExistingTable(originalName, newName);
    long newId = hbaseMetadata.getTableId(newName);
    assertEquals(origId, newId);
    Collection<ColumnSchema> origSchemaColumns = origSchema.getColumns();
    TableSchema newSchema = hbaseMetadata.getSchema(newId);
    for (ColumnSchema columnSchema : newSchema.getColumns()) {
        assertTrue(origSchemaColumns.contains(columnSchema));
    }
    // Trying to access the id of the old table name will result in an exception
    hbaseMetadata.getTableId(originalName);
    hTableSpy.close();
}
Also used : TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) Test(org.junit.Test)

Example 22 with ColumnSchema

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

the class RowKeyTest method testIndexRowKeyStrings.

@Test
public void testIndexRowKeyStrings() {
    String columnName = "c1";
    String indexName = "i1";
    ColumnSchema columnSchema = ColumnSchema.builder("default", ColumnType.DATETIME).build();
    IndexSchema indexSchema = new IndexSchema(indexName, ImmutableList.of(columnName), false);
    TableSchema tableSchema = new TableSchema(ImmutableList.of(columnSchema), ImmutableList.of(indexSchema));
    Generator<RowKey> rowkeysGen = RowKeyGenerator.getAscIndexRowKeyGenerator(tableSchema);
    List<RowKey> rowkeys = Lists.newArrayList(Iterables.toIterable(rowkeysGen));
    Collections.sort(rowkeys);
    List<byte[]> encodedRowkeys = Lists.newArrayList();
    for (RowKey rowkey : rowkeys) {
        encodedRowkeys.add(rowkey.encode());
    }
    Collections.sort(encodedRowkeys, new Bytes.ByteArrayComparator());
    for (int i = 0; i < rowkeys.size(); i++) {
        RowKey rowKey = rowkeys.get(i);
        byte[] encodedRowKey = encodedRowkeys.get(i);
        Assert.assertArrayEquals(encodedRowKey, rowKey.encode());
    }
}
Also used : UnsignedBytes(com.google.common.primitives.UnsignedBytes) Bytes(org.apache.hadoop.hbase.util.Bytes) TableSchema(com.nearinfinity.honeycomb.mysql.schema.TableSchema) RowKey(com.nearinfinity.honeycomb.hbase.rowkey.RowKey) ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) Test(org.junit.Test)

Example 23 with ColumnSchema

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

the class FieldParserTest method testParseBinaryEmptyValue.

@Test
public void testParseBinaryEmptyValue() throws ParseException {
    ColumnSchema schema = ColumnSchema.builder(COLUMN_NAME, ColumnType.BINARY).setMaxLength(32).build();
    assertEquals(ByteBuffer.wrap(EMPTY_STRING.getBytes(Charsets.UTF_8)), FieldParser.parse(EMPTY_STRING, schema));
}
Also used : ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) Test(org.junit.Test)

Example 24 with ColumnSchema

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

the class FieldParserTest method testParseStringEmptyValue.

@Test
public void testParseStringEmptyValue() throws ParseException {
    ColumnSchema schema = ColumnSchema.builder(COLUMN_NAME, ColumnType.STRING).setMaxLength(32).build();
    assertEquals(ByteBuffer.wrap(EMPTY_STRING.getBytes(Charsets.UTF_8)), FieldParser.parse(EMPTY_STRING, schema));
}
Also used : ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) Test(org.junit.Test)

Example 25 with ColumnSchema

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

the class FieldParserTest method testParseULongNegativeInput.

@Test(expected = IllegalArgumentException.class)
public void testParseULongNegativeInput() throws ParseException {
    ColumnSchema schema = ColumnSchema.builder(COLUMN_NAME, ColumnType.ULONG).build();
    FieldParser.parse("-123", schema);
}
Also used : ColumnSchema(com.nearinfinity.honeycomb.mysql.schema.ColumnSchema) Test(org.junit.Test)

Aggregations

ColumnSchema (com.nearinfinity.honeycomb.mysql.schema.ColumnSchema)28 Test (org.junit.Test)22 TableSchema (com.nearinfinity.honeycomb.mysql.schema.TableSchema)9 IndexSchema (com.nearinfinity.honeycomb.mysql.schema.IndexSchema)5 Predicate (com.google.common.base.Predicate)1 ImmutableList (com.google.common.collect.ImmutableList)1 UnsignedBytes (com.google.common.primitives.UnsignedBytes)1 RowKey (com.nearinfinity.honeycomb.hbase.rowkey.RowKey)1 HandlerProxy (com.nearinfinity.honeycomb.mysql.HandlerProxy)1 Row (com.nearinfinity.honeycomb.mysql.Row)1 ColumnType (com.nearinfinity.honeycomb.mysql.gen.ColumnType)1 HoneycombIntegrationTest (integrationtests.HoneycombIntegrationTest)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)1 Bytes (org.apache.hadoop.hbase.util.Bytes)1