Search in sources :

Example 6 with ChangeSet

use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.

the class XmlHbaseSchemaParserTest method parseSchema.

@Test
public void parseSchema() {
    final String schemaFile = "hbase-schema/test-hbase-schema.xml";
    TableConfiguration expectedChangeSet1_tableConfiguration = new TableConfiguration.Builder().durability(TableConfiguration.Durability.ASYNC_WAL).build();
    List<ColumnFamilyChange> expectedChangeSet1_columnFamilies = Arrays.asList(new CreateColumnFamilyChange("CF1", new ColumnFamilyConfiguration.Builder().timeToLive(86400).dataBlockEncoding(ColumnFamilyConfiguration.DataBlockEncoding.NONE).build()), new CreateColumnFamilyChange("CF2", ColumnFamilyConfiguration.EMPTY_CONFIGURATION));
    CreateTableChange.SplitOption expectedChangeSet1_tableSplitOption = new CreateTableChange.SplitOption.Auto(16);
    TableChange expectedChangeSet1_tableChange = new CreateTableChange("Table1", expectedChangeSet1_tableConfiguration, expectedChangeSet1_columnFamilies, expectedChangeSet1_tableSplitOption);
    List<ColumnFamilyChange> expectedChangeSet2_columnFamilies = Arrays.asList(new CreateColumnFamilyChange("CF3", ColumnFamilyConfiguration.EMPTY_CONFIGURATION));
    TableChange expectedChangeSet2_tableChange = new ModifyTableChange("Table1", TableConfiguration.EMPTY_CONFIGURATION, expectedChangeSet2_columnFamilies);
    InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(schemaFile);
    XmlHbaseSchemaParseResult parseResult = parser.parseSchema(new InputSource(inputStream));
    List<String> includeFiles = new ArrayList<>(parseResult.getIncludeFiles());
    assertThat(includeFiles.size(), is(1));
    String includeFile = includeFiles.get(0);
    assertThat(includeFile, is("test-hbase-schema-include.xml"));
    List<ChangeSet> changeSets = new ArrayList<>(parseResult.getChangeSets());
    assertThat(changeSets.size(), is(2));
    ChangeSet changeSet1 = changeSets.get(0);
    assertThat(changeSet1.getId(), is("id-1"));
    assertThat(changeSet1.getTableChanges(), is(Arrays.asList(expectedChangeSet1_tableChange)));
    ChangeSet changeSet2 = changeSets.get(1);
    assertThat(changeSet2.getId(), is("id-2"));
    assertThat(changeSet2.getTableChanges(), is(Arrays.asList(expectedChangeSet2_tableChange)));
}
Also used : CreateColumnFamilyChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateColumnFamilyChange) InputSource(org.xml.sax.InputSource) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) CreateColumnFamilyChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateColumnFamilyChange) ColumnFamilyChange(com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyChange) ModifyTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.ModifyTableChange) CreateTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) TableConfiguration(com.navercorp.pinpoint.hbase.schema.reader.core.TableConfiguration) ColumnFamilyConfiguration(com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyConfiguration) CreateTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange) TableChange(com.navercorp.pinpoint.hbase.schema.reader.core.TableChange) ModifyTableChange(com.navercorp.pinpoint.hbase.schema.reader.core.ModifyTableChange) Test(org.junit.Test)

Example 7 with ChangeSet

use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.

the class ChangeSetManagerTest method getExecutedChangeSets.

@Test
public void getExecutedChangeSets() {
    ChangeSet changeSet1 = newChangeSet("id1", "value1");
    ChangeSet changeSet2 = newChangeSet("id2", "value2");
    ChangeSet changeSet3 = newChangeSet("id3", "value3");
    ChangeSet changeSet4 = newChangeSet("id4", "value4");
    List<ChangeSet> changeSets = Arrays.asList(changeSet1, changeSet2, changeSet3, changeSet4);
    List<SchemaChangeLog> schemaChangeLogs = newSchemaChangeLogs(changeSet1, changeSet2);
    ChangeSetManager changeSetManager = new ChangeSetManager(changeSets);
    List<ChangeSet> executedChangeSets = changeSetManager.getExecutedChangeSets(schemaChangeLogs);
    assertThat(executedChangeSets, contains(changeSet1, changeSet2));
}
Also used : ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) Test(org.junit.Test)

Example 8 with ChangeSet

use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.

the class ChangeSetManagerTest method getExecutedChangeSets_largerSchemaChangeLogs.

@Test
public void getExecutedChangeSets_largerSchemaChangeLogs() {
    ChangeSet changeSet = newChangeSet("id1", "value1");
    ChangeSetManager changeSetManager = new ChangeSetManager(Arrays.asList(changeSet));
    List<SchemaChangeLog> schemaChangeLogs = Arrays.asList(newSchemaChangeLog("id1", "value1", 1), newSchemaChangeLog("id2", "value2", 2));
    List<ChangeSet> executedChangeSets = changeSetManager.getExecutedChangeSets(schemaChangeLogs);
    assertThat(executedChangeSets, hasSize(1));
    assertThat(executedChangeSets, contains(changeSet));
}
Also used : ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) Test(org.junit.Test)

Example 9 with ChangeSet

use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.

the class ChangeSetManagerTest method filterExecutedChangeSets_invalidCheckSum.

@Test(expected = IllegalArgumentException.class)
public void filterExecutedChangeSets_invalidCheckSum() {
    ChangeSet changeSet = newChangeSet("id1", "value1");
    List<ChangeSet> changeSets = Arrays.asList(changeSet);
    CheckSum invalidCheckSum = CheckSum.compute(CheckSum.getCurrentVersion(), "value2");
    List<SchemaChangeLog> schemaChangeLogs = Arrays.asList(newSchemaChangeLog("id1", "value1", invalidCheckSum, 1));
    ChangeSetManager changeSetManager = new ChangeSetManager(changeSets);
    changeSetManager.filterExecutedChangeSets(schemaChangeLogs);
}
Also used : ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog) Test(org.junit.Test)

Example 10 with ChangeSet

use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.

the class ChangeSetManagerTest method newSchemaChangeLogs.

private List<SchemaChangeLog> newSchemaChangeLogs(ChangeSet... changeSets) {
    List<SchemaChangeLog> schemaChangeLogs = new ArrayList<>();
    int execOrder = 1;
    for (ChangeSet changeSet : changeSets) {
        schemaChangeLogs.add(new SchemaChangeLog.Builder().id(changeSet.getId()).value(changeSet.getValue()).checkSum(CheckSum.compute(CheckSum.getCurrentVersion(), changeSet.getValue())).execOrder(execOrder++).build());
    }
    return schemaChangeLogs;
}
Also used : ArrayList(java.util.ArrayList) ChangeSet(com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet) SchemaChangeLog(com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)

Aggregations

ChangeSet (com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet)39 Test (org.junit.Test)28 SchemaChangeLog (com.navercorp.pinpoint.hbase.schema.domain.SchemaChangeLog)23 ArrayList (java.util.ArrayList)8 TableChange (com.navercorp.pinpoint.hbase.schema.reader.core.TableChange)7 CreateTableChange (com.navercorp.pinpoint.hbase.schema.reader.core.CreateTableChange)6 ModifyTableChange (com.navercorp.pinpoint.hbase.schema.reader.core.ModifyTableChange)6 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)6 HbaseSchemaStatus (com.navercorp.pinpoint.hbase.schema.core.HbaseSchemaStatus)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 CreateColumnFamilyChange (com.navercorp.pinpoint.hbase.schema.reader.core.CreateColumnFamilyChange)4 ColumnFamilyChange (com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyChange)3 HbaseAdminOperation (com.navercorp.pinpoint.common.hbase.HbaseAdminOperation)2 ChangeSetManager (com.navercorp.pinpoint.hbase.schema.core.ChangeSetManager)2 HbaseSchemaCommandManager (com.navercorp.pinpoint.hbase.schema.core.command.HbaseSchemaCommandManager)2 InvalidHbaseSchemaException (com.navercorp.pinpoint.hbase.schema.reader.InvalidHbaseSchemaException)2 ColumnFamilyConfiguration (com.navercorp.pinpoint.hbase.schema.reader.core.ColumnFamilyConfiguration)2 TableCommand (com.navercorp.pinpoint.hbase.schema.core.command.TableCommand)1 HbaseSchemaParseException (com.navercorp.pinpoint.hbase.schema.reader.HbaseSchemaParseException)1 TableConfiguration (com.navercorp.pinpoint.hbase.schema.reader.core.TableConfiguration)1