use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.
the class HbaseSchemaCommandManagerTest method shouldFilterTablesFromDifferentNamespace.
@Test
public void shouldFilterTablesFromDifferentNamespace() {
String namespace = "namespace";
String differentNamespace = "differentNamespace";
String tableName = "table1";
HTableDescriptor sameNamespaceHtd = createHtd(namespace, tableName, "CF1");
HTableDescriptor differentNamespaceHtd = createHtd(differentNamespace, tableName, "CF1");
List<HTableDescriptor> htds = Arrays.asList(sameNamespaceHtd, differentNamespaceHtd);
HbaseSchemaCommandManager manager = new HbaseSchemaCommandManager(namespace, null, htds);
ColumnFamilyChange createColumnFamilyChange = newColumnFamilyChange("CF2");
TableChange modifyTableChange = newTableChange(ChangeType.MODIFY, tableName, createColumnFamilyChange);
ChangeSet modifyTableChangeSet = newChangeSet(modifyTableChange);
manager.applyChangeSet(modifyTableChangeSet);
List<HTableDescriptor> schemaSnapshot = manager.getSchemaSnapshot();
assertThat(schemaSnapshot, contains(sameNamespaceHtd));
assertThat(schemaSnapshot, not(contains(differentNamespaceHtd)));
}
use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.
the class ChangeSetManager method getExecutedChangeSets.
/**
* Returns a new list of {@link ChangeSet} that has already been executed as specified by {@code schemaChangeLogs}.
*
* @param schemaChangeLogs logs of change sets already executed
* @return a list of change sets already executed
* @throws IllegalArgumentException if the current change sets are not valid for the specified{@code schemaChangeLogs}
*/
public List<ChangeSet> getExecutedChangeSets(List<SchemaChangeLog> schemaChangeLogs) {
if (CollectionUtils.isEmpty(schemaChangeLogs)) {
return Collections.emptyList();
}
List<SchemaChangeLog> sortedSchemaChangeLogs = sortSchemaChangeLogs(schemaChangeLogs);
List<ChangeSet> executedChangeSets = new ArrayList<>();
for (int i = 0; i < changeSets.size() && i < sortedSchemaChangeLogs.size(); i++) {
ChangeSet changeSet = changeSets.get(i);
SchemaChangeLog executedSchemaChangeLog = sortedSchemaChangeLogs.get(i);
int expectedOrder = i + 1;
verifyChangeLog(executedSchemaChangeLog, changeSet, expectedOrder);
executedChangeSets.add(changeSet);
}
return executedChangeSets;
}
use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.
the class ChangeSetManager method filterExecutedChangeSets.
/**
* Returns a new list of {@link ChangeSet} that has not been executed as specified by {@code schemaChangeLogs}.
*
* @param schemaChangeLogs logs of change sets already executed
* @return a list of change sets not yet executed
* @throws IllegalArgumentException if the current change sets are not valid for the specified{@code schemaChangeLogs}
*/
public List<ChangeSet> filterExecutedChangeSets(List<SchemaChangeLog> schemaChangeLogs) {
if (CollectionUtils.isEmpty(schemaChangeLogs)) {
return new ArrayList<>(changeSets);
}
List<SchemaChangeLog> sortedSchemaChangeLogs = sortSchemaChangeLogs(schemaChangeLogs);
int i = 0;
while (i < changeSets.size() && i < sortedSchemaChangeLogs.size()) {
ChangeSet changeSet = changeSets.get(i);
SchemaChangeLog executedSchemaChangeLog = sortedSchemaChangeLogs.get(i);
int expectedOrder = i + 1;
verifyChangeLog(executedSchemaChangeLog, changeSet, expectedOrder);
i++;
}
if (i >= changeSets.size()) {
return Collections.emptyList();
}
return new ArrayList<>(changeSets.subList(i, changeSets.size()));
}
use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.
the class SchemaChangeLogServiceImplTest method recordChangeSets.
@Test
public void recordChangeSets() {
// Given
final int numChangeSets = random.nextInt(100) + 1;
final List<ChangeSet> changeSets = new ArrayList<>(numChangeSets);
for (int i = 0; i < numChangeSets; i++) {
changeSets.add(newChangeSet("id" + (i + 1)));
}
doNothing().when(schemaChangeLogDao).insertChangeLog(anyString(), any(SchemaChangeLog.class));
// When
List<SchemaChangeLog> schemaChangeLogs = schemaChangeLogService.recordChangeSets("namespace", changeSets);
// Then
MatcherAssert.assertThat(schemaChangeLogs.size(), equalTo(numChangeSets));
final int initialExecOrder = 1;
for (int i = 0; i < numChangeSets; i++) {
SchemaChangeLog schemaChangeLog = schemaChangeLogs.get(i);
ChangeSet changeSet = changeSets.get(i);
MatcherAssert.assertThat(schemaChangeLog.getId(), equalTo(changeSet.getId()));
int expectedExecOrder = initialExecOrder + i;
MatcherAssert.assertThat(schemaChangeLog.getExecOrder(), equalTo(expectedExecOrder));
}
}
use of com.navercorp.pinpoint.hbase.schema.reader.core.ChangeSet in project pinpoint by naver.
the class SchemaChangeLogServiceImplTest method recordChangeSet.
@Test
public void recordChangeSet() {
// Given
final ChangeSet changeSet = newChangeSet("id1");
doNothing().when(schemaChangeLogDao).insertChangeLog(anyString(), any(SchemaChangeLog.class));
// When
SchemaChangeLog schemaChangeLog = schemaChangeLogService.recordChangeSet("namespace", changeSet);
// Then
MatcherAssert.assertThat(schemaChangeLog.getId(), equalTo(changeSet.getId()));
MatcherAssert.assertThat(schemaChangeLog.getExecOrder(), equalTo(1));
}
Aggregations