@Test
public void testCreateDeleteTableWithSecondaryIndex() throws IOException {

  // create normal table with secondary index table prefix
  HTableDescriptor tableDesc = new HTableDescriptor(
      IndexMasterObserver.THEMIS_SECONDARY_INDEX_TABLE_NAME_PREFIX + "_a");
  try {
    admin.createTable(tableDesc);
    Assert.fail();
  } catch (IOException e) {
    Assert.assertTrue(e.getMessage().indexOf("is preserved") >= 0);
  }
  
  byte[] testMainTable = Bytes.toBytes("temp_test");
  byte[] testIndexTable = Bytes.toBytes("__themis_index_temp_test_ThemisCF_Qualifier_test_index");
  deleteTable(admin, testMainTable);
  // create themis table without index enable
  tableDesc = new HTableDescriptor(testMainTable);
  tableDesc.addFamily(IndexMasterObserver.getSecondaryIndexFamily());
  admin.createTable(tableDesc);
  HTableDescriptor[] tableDescs = admin.listTables();
  for (HTableDescriptor desc : tableDescs) {
    Assert.assertFalse(Bytes.equals(testIndexTable, desc.getName()));
  }
  admin.disableTable(testMainTable);
  admin.deleteTable(testMainTable);
  
  // create table with index attribute but without themis enable key
  tableDesc = new HTableDescriptor(testMainTable);
  HColumnDescriptor columnDesc = new HColumnDescriptor(INDEX_FAMILY);
  columnDesc.setValue(IndexMasterObserver.THEMIS_SECONDARY_INDEX_FAMILY_ATTRIBUTE_KEY,
    Boolean.TRUE.toString());
  tableDesc.addFamily(columnDesc);
  try {
    admin.createTable(tableDesc);
  } catch (IOException e) {
    Assert.assertTrue(e.getMessage().indexOf("must be set on themis-enabled family") >= 0);
  }
  
  // create themis table with secondary index attribute
  
  createTableForIndexTest(testMainTable);
  HTableDescriptor desc = admin.getTableDescriptor(testMainTable);
  Assert.assertNotNull(desc);
  Assert.assertNotNull(desc.getFamily(ColumnUtil.LOCK_FAMILY_NAME));
  desc = admin.getTableDescriptor(testIndexTable);
  Assert.assertNotNull(desc);
  Assert.assertNotNull(desc.getFamily(Bytes
      .toBytes(IndexMasterObserver.THEMIS_SECONDARY_INDEX_TABLE_FAMILY)));
  Assert.assertNotNull(desc.getFamily(ColumnUtil.LOCK_FAMILY_NAME));
  
  deleteTableForIndexTest(testMainTable);
  tableDescs = admin.listTables();
  for (HTableDescriptor tempDesc : tableDescs) {
    if (Bytes.equals(tempDesc.getName(), testMainTable)) {
      Assert.fail("fail to delete table:" + Bytes.toString(testMainTable));
    } else if (Bytes.equals(tempDesc.getName(), testIndexTable)) {
      Assert.fail("fail to delete table:" + Bytes.toString(testIndexTable));
    }
  }
}