Search in sources :

Example 1 with HbaseAdminOperation

use of com.navercorp.pinpoint.common.hbase.HbaseAdminOperation in project pinpoint by naver.

the class HbaseSchemaCommandManagerTest method modifyingTheSameTableMultipleTimesShouldBeMerged.

@Test
public void modifyingTheSameTableMultipleTimesShouldBeMerged() {
    String namespace = "namespace";
    String tableName = "table";
    String existingColumnFamily = "CF";
    String newColumnFamily1 = "CF1";
    String newColumnFamily2 = "CF2";
    HTableDescriptor existingHtd = createHtd(namespace, tableName, existingColumnFamily);
    HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null, Arrays.asList(new HTableDescriptor(existingHtd)));
    ChangeSet createColumnFamilyChangeSet1 = newChangeSet(newTableChange(ChangeType.MODIFY, tableName, newColumnFamilyChange(newColumnFamily1)));
    ChangeSet createColumnFamilyChangeSet2 = newChangeSet(newTableChange(ChangeType.MODIFY, tableName, newColumnFamilyChange(newColumnFamily2)));
    manager.applyChangeSet(createColumnFamilyChangeSet1);
    manager.applyChangeSet(createColumnFamilyChangeSet2);
    // verify schema snapshot
    List<HTableDescriptor> schemaSnapshot = manager.getSchemaSnapshot();
    assertThat(schemaSnapshot.size(), is(1));
    HTableDescriptor snapshotTable = schemaSnapshot.get(0);
    assertThat(snapshotTable.getTableName(), is(TableName.valueOf(namespace, tableName)));
    List<String> snapshotColumnFamilies = snapshotTable.getFamilies().stream().map(HColumnDescriptor::getNameAsString).collect(Collectors.toList());
    assertThat(snapshotColumnFamilies, contains(existingColumnFamily, newColumnFamily1, newColumnFamily2));
    // verify command - should add 2 column families
    HbaseAdminOperation mockHbaseAdminOperation = Mockito.mock(HbaseAdminOperation.class);
    when(mockHbaseAdminOperation.getTableDescriptor(existingHtd.getTableName())).thenReturn(existingHtd);
    doNothing().when(mockHbaseAdminOperation).addColumn(any(TableName.class), any(HColumnDescriptor.class));
    doNothing().when(mockHbaseAdminOperation).createTable(any(HTableDescriptor.class));
    for (TableCommand tableCommand : manager.getCommands()) {
        tableCommand.execute(mockHbaseAdminOperation);
    }
    verify(mockHbaseAdminOperation, times(2)).addColumn(any(TableName.class), any(HColumnDescriptor.class));
    verify(mockHbaseAdminOperation, never()).createTable(any(HTableDescriptor.class));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HbaseAdminOperation(com.navercorp.pinpoint.common.hbase.HbaseAdminOperation) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Example 2 with HbaseAdminOperation

use of com.navercorp.pinpoint.common.hbase.HbaseAdminOperation in project pinpoint by naver.

the class HbaseSchemaCommandManagerTest method creatingAndModifyingTheSameTableShouldBeMerged.

@Test
public void creatingAndModifyingTheSameTableShouldBeMerged() {
    String namespace = "namespace";
    String tableName = "table";
    String columnFamily1 = "CF1";
    String columnFamily2 = "CF2";
    String columnFamily3 = "CF3";
    HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null);
    ChangeSet createTableChangeSet = newChangeSet(newTableChange(ChangeType.CREATE, tableName, newColumnFamilyChange(columnFamily1)));
    ChangeSet addColumnFamilyChangeSet1 = newChangeSet(newTableChange(ChangeType.MODIFY, tableName, newColumnFamilyChange(columnFamily2)));
    ChangeSet addColumnFamilyChangeSet2 = newChangeSet(newTableChange(ChangeType.MODIFY, tableName, newColumnFamilyChange(columnFamily3)));
    manager.applyChangeSet(createTableChangeSet);
    manager.applyChangeSet(addColumnFamilyChangeSet1);
    manager.applyChangeSet(addColumnFamilyChangeSet2);
    // verify schema snapshot
    List<HTableDescriptor> schemaSnapshot = manager.getSchemaSnapshot();
    assertThat(schemaSnapshot.size(), is(1));
    HTableDescriptor snapshotTable = schemaSnapshot.get(0);
    assertThat(snapshotTable.getTableName(), is(TableName.valueOf(namespace, tableName)));
    List<String> snapshotColumnFamilies = snapshotTable.getFamilies().stream().map(HColumnDescriptor::getNameAsString).collect(Collectors.toList());
    assertThat(snapshotColumnFamilies, contains(columnFamily1, columnFamily2, columnFamily3));
    // verify command - should create 1 table (with all 3 column families)
    HbaseAdminOperation mockHbaseAdminOperation = Mockito.mock(HbaseAdminOperation.class);
    when(mockHbaseAdminOperation.tableExists(TableName.valueOf(namespace, tableName))).thenReturn(false);
    doNothing().when(mockHbaseAdminOperation).createTable(any(HTableDescriptor.class));
    for (TableCommand tableCommand : manager.getCommands()) {
        tableCommand.execute(mockHbaseAdminOperation);
    }
    verify(mockHbaseAdminOperation, times(1)).createTable(any(HTableDescriptor.class));
}
Also used : HbaseAdminOperation(com.navercorp.pinpoint.common.hbase.HbaseAdminOperation) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) Test(org.junit.Test)

Aggregations

HbaseAdminOperation (com.navercorp.pinpoint.common.hbase.HbaseAdminOperation)2 ChangeSet (com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet)2 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)2 Test (org.junit.Test)2 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)1 TableName (org.apache.hadoop.hbase.TableName)1