Search in sources :

Example 11 with QueryKey

use of com.nearinfinity.honeycomb.mysql.QueryKey in project honeycomb by altamiracorp.

the class IndexOperationsIT method testDropIndex.

@Test(expected = NullPointerException.class)
public void testDropIndex() {
    final int keyValue = 7;
    final QueryKey key = ITUtils.createKey(keyValue, QueryType.EXACT_KEY);
    // Add data rows to index
    ITUtils.insertData(proxy, ROW_COUNT, keyValue);
    // Verify that we can get a row from the index scan
    proxy.startIndexScan(key.serialize());
    final Row row = Row.deserialize(proxy.getNextRow());
    byte[] result = proxy.getRow(Util.UUIDToBytes(row.getUUID()));
    assertNotNull(row);
    assertEquals(Row.deserialize(result).getUUID(), row.getUUID());
    proxy.endScan();
    // Drop the index from the table
    proxy.dropIndex(TestConstants.INDEX1);
    // Verify that the data row is still available after the index has been removed
    result = proxy.getRow(Util.UUIDToBytes(row.getUUID()));
    assertEquals(Row.deserialize(result).getUUID(), row.getUUID());
    // Verify that the scan is unable to execute
    proxy.startIndexScan(key.serialize());
}
Also used : QueryKey(com.nearinfinity.honeycomb.mysql.QueryKey) Row(com.nearinfinity.honeycomb.mysql.Row) HoneycombIntegrationTest(integrationtests.HoneycombIntegrationTest) Test(org.junit.Test)

Example 12 with QueryKey

use of com.nearinfinity.honeycomb.mysql.QueryKey in project honeycomb by altamiracorp.

the class IndexOperationsIT method testAddIndex.

@Test
public void testAddIndex() {
    final IndexSchema indexSchema = new IndexSchema(NEW_INDEX_NAME, Lists.newArrayList(TestConstants.COLUMN1), false);
    // Add data rows to index
    ITUtils.insertData(proxy, ROW_COUNT, INDEX_COL_VALUE);
    // Add the new index to the table
    proxy.addIndex(NEW_INDEX_NAME, indexSchema.serialize());
    // Perform a scan with the new index
    final QueryKey key = new QueryKey(NEW_INDEX_NAME, QueryType.EXACT_KEY, ImmutableMap.<String, ByteBuffer>of(TestConstants.COLUMN1, ITUtils.encodeValue(INDEX_COL_VALUE)));
    ITUtils.assertReceivingDifferentRows(proxy, key, ROW_COUNT);
}
Also used : QueryKey(com.nearinfinity.honeycomb.mysql.QueryKey) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) HoneycombIntegrationTest(integrationtests.HoneycombIntegrationTest) Test(org.junit.Test)

Example 13 with QueryKey

use of com.nearinfinity.honeycomb.mysql.QueryKey in project honeycomb by altamiracorp.

the class IndexOperationsIT method testAddCompoundIndex.

@Test
public void testAddCompoundIndex() {
    // Create the compound index ordered as (col2, col1)
    final IndexSchema indexSchema = new IndexSchema(NEW_INDEX_NAME, Lists.newArrayList(TestConstants.COLUMN2, TestConstants.COLUMN1), false);
    final int column2Value = 0;
    // Add data rows to index
    ITUtils.insertData(proxy, ROW_COUNT, INDEX_COL_VALUE);
    // Add the new index to the table
    proxy.addIndex(NEW_INDEX_NAME, indexSchema.serialize());
    // Perform a scan with the new index
    final QueryKey key = new QueryKey(NEW_INDEX_NAME, QueryType.EXACT_KEY, ImmutableMap.<String, ByteBuffer>of(TestConstants.COLUMN1, ITUtils.encodeValue(INDEX_COL_VALUE), TestConstants.COLUMN2, ITUtils.encodeValue(column2Value)));
    ITUtils.assertReceivingDifferentRows(proxy, key, ROW_COUNT);
}
Also used : QueryKey(com.nearinfinity.honeycomb.mysql.QueryKey) IndexSchema(com.nearinfinity.honeycomb.mysql.schema.IndexSchema) HoneycombIntegrationTest(integrationtests.HoneycombIntegrationTest) Test(org.junit.Test)

Example 14 with QueryKey

use of com.nearinfinity.honeycomb.mysql.QueryKey in project honeycomb by altamiracorp.

the class RowOperationsIT method testGetRow.

@Test
public void testGetRow() {
    ITUtils.insertData(proxy, ROW_COUNT, INDEX_COL_VALUE);
    final QueryKey key = ITUtils.createKey(INDEX_COL_VALUE, QueryType.EXACT_KEY);
    proxy.startIndexScan(key.serialize());
    final Row r = Row.deserialize(proxy.getNextRow());
    final byte[] result = proxy.getRow(Util.UUIDToBytes(r.getUUID()));
    assertNotNull(result);
    assertThat(Row.deserialize(result).getUUID(), equalTo(r.getUUID()));
}
Also used : QueryKey(com.nearinfinity.honeycomb.mysql.QueryKey) Row(com.nearinfinity.honeycomb.mysql.Row) HoneycombIntegrationTest(integrationtests.HoneycombIntegrationTest) Test(org.junit.Test)

Example 15 with QueryKey

use of com.nearinfinity.honeycomb.mysql.QueryKey in project honeycomb by altamiracorp.

the class RowOperationsIT method testDeleteRow.

@Test
public void testDeleteRow() {
    final Map<String, ByteBuffer> map = Maps.newHashMap();
    map.put(TestConstants.COLUMN1, ITUtils.encodeValue(INDEX_COL_VALUE));
    map.put(TestConstants.COLUMN2, ITUtils.encodeValue(6));
    final Row row = new Row(map, UUID.randomUUID());
    proxy.insertRow(row.serialize());
    proxy.flush();
    final QueryKey key = ITUtils.createKey(INDEX_COL_VALUE, QueryType.EXACT_KEY);
    proxy.startIndexScan(key.serialize());
    proxy.deleteRow(proxy.getNextRow());
    proxy.flush();
}
Also used : QueryKey(com.nearinfinity.honeycomb.mysql.QueryKey) Row(com.nearinfinity.honeycomb.mysql.Row) ByteBuffer(java.nio.ByteBuffer) HoneycombIntegrationTest(integrationtests.HoneycombIntegrationTest) Test(org.junit.Test)

Aggregations

QueryKey (com.nearinfinity.honeycomb.mysql.QueryKey)17 Test (org.junit.Test)16 HoneycombIntegrationTest (integrationtests.HoneycombIntegrationTest)14 Row (com.nearinfinity.honeycomb.mysql.Row)6 ByteBuffer (java.nio.ByteBuffer)6 IndexSchema (com.nearinfinity.honeycomb.mysql.schema.IndexSchema)3