use of com.emc.storageos.db.client.impl.CompositeColumnName in project coprhd-controller by CoprHD.
the class RowMutationTest method setupTest.
@Before
public void setupTest() {
volumeCF = new ColumnFamily<String, CompositeColumnName>("Volume", StringSerializer.get(), CompositeColumnNameSerializer.get());
indexCF = new ColumnFamily<String, IndexColumnName>("LabelPrefixIndex", StringSerializer.get(), IndexColumnNameSerializer.get());
noExistCF = new ColumnFamily<String, CompositeColumnName>("no_exits_CF", StringSerializer.get(), CompositeColumnNameSerializer.get());
rowMutator = new RowMutator(((DbClientImpl) this.getDbClient()).getLocalContext().getKeyspace(), false);
}
use of com.emc.storageos.db.client.impl.CompositeColumnName in project coprhd-controller by CoprHD.
the class RowMutationTest method testTimeUUID.
@Test
public void testTimeUUID() throws Exception {
Volume volume = new Volume();
URI id1 = URIUtil.createId(Volume.class);
URI pool1 = URIUtil.createId(StoragePool.class);
volume.setId(id1);
volume.setLabel("volume1");
volume.setPool(pool1);
volume.setInactive(false);
volume.setAllocatedCapacity(1000L);
volume.setProvisionedCapacity(2000L);
volume.setAssociatedSourceVolume(URI.create("test"));
volume.setVolumeGroupIds(new StringSet(Sets.newHashSet("v1", "v2")));
getDbClient().updateObject(volume);
DataObjectType doType = TypeMap.getDoType(Volume.class);
OperationResult<ColumnList<CompositeColumnName>> result = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace().prepareQuery(doType.getCF()).getKey(volume.getId().toString()).execute();
List<Long> columnTimeUUIDStamps = new ArrayList<Long>();
for (Column<CompositeColumnName> column : result.getResult()) {
if (column.getName().getTimeUUID() != null) {
columnTimeUUIDStamps.add(TimeUUIDUtils.getMicrosTimeFromUUID(column.getName().getTimeUUID()));
}
}
Collections.sort(columnTimeUUIDStamps);
for (int i = 1; i < columnTimeUUIDStamps.size(); i++) {
Assert.assertEquals(1, columnTimeUUIDStamps.get(i) - columnTimeUUIDStamps.get(i - 1));
}
}
use of com.emc.storageos.db.client.impl.CompositeColumnName in project coprhd-controller by CoprHD.
the class RowMutationTest method insertRecordAndIndexColumn.
@Test
public void insertRecordAndIndexColumn() throws ConnectionException {
String rowKey = URIUtil.createId(Volume.class).toString();
String volumeLabel = "volume label";
// insert data object
ColumnListMutation<CompositeColumnName> columnList = rowMutator.getRecordColumnList(volumeCF, rowKey);
columnList.putColumn(new CompositeColumnName("allocatedCapacity"), 20);
columnList.putColumn(new CompositeColumnName("label"), volumeLabel);
// insert related index
rowMutator.getIndexColumnList(indexCF, "vo").putColumn(new IndexColumnName("Volume", volumeLabel, volumeLabel, rowKey, rowMutator.getTimeUUID()), "");
rowMutator.execute();
// verify data object information
Volume volume = (Volume) this.getDbClient().queryObject(URI.create(rowKey));
Assert.assertNotNull(volume);
Assert.assertEquals(volume.getAllocatedCapacity().longValue(), 20L);
Assert.assertEquals(volume.getLabel(), volumeLabel);
// verify index information
CqlStatement statement = ((DbClientImpl) this.getDbClient()).getLocalContext().getKeyspace().prepareCqlStatement();
String cql = String.format("select * from \"LabelPrefixIndex\" where key='%s' and column1='Volume' and column2='%s' and column3='%s' and column4='%s'", "vo", volumeLabel, volumeLabel, rowKey);
CqlStatementResult result = statement.withCql(cql).execute().getResult();
Rows<String, IndexColumnName> rows = result.getRows(indexCF);
Assert.assertEquals(rows.size(), 1);
}
use of com.emc.storageos.db.client.impl.CompositeColumnName in project coprhd-controller by CoprHD.
the class RebuildIndexDuplicatedCFNameMigrationTest method testHandleDataObjectClass.
@Test
public void testHandleDataObjectClass() throws Exception {
DataObjectType doType = TypeMap.getDoType(FileShare.class);
for (int i = 0; i < 5; i++) {
FileShare testData = new FileShare();
testData.setId(URIUtil.createId(FileShare.class));
testData.setPath("duplicated_value" + i);
testData.setMountPath("duplicated_value" + i);
getDbClient().updateObject(testData);
}
// create data object whose index are neede to be rebuild
resetRowMutatorTimeStampOffSet(0);
FileShare[] testDataArray = new FileShare[10];
for (int i = 0; i < 10; i++) {
FileShare testData = new FileShare();
testData.setId(URIUtil.createId(FileShare.class));
testData.setPath("duplicated_value" + i);
testData.setMountPath("duplicated_value" + i);
testDataArray[i] = testData;
getDbClient().updateObject(testData);
}
resetRowMutatorTimeStampOffSet(1);
target = new RebuildIndexDuplicatedCFNameMigration();
target.setDbClient(getDbClient());
target.process();
assertEquals(testDataArray.length, target.getTotalProcessedIndexCount());
for (FileShare testData : testDataArray) {
FileShare targetData = (FileShare) getDbClient().queryObject(testData.getId());
assertEquals(testData.getPath(), targetData.getPath());
assertEquals(testData.getMountPath(), targetData.getMountPath());
OperationResult<ColumnList<CompositeColumnName>> result = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace().prepareQuery(doType.getCF()).getKey(testData.getId().toString()).execute();
long pathTime = 0;
long mountPathTime = 0;
for (Column<CompositeColumnName> column : result.getResult()) {
if (column.getName().getOne().equals("path")) {
pathTime = TimeUUIDUtils.getMicrosTimeFromUUID(column.getName().getTimeUUID());
} else if (column.getName().getOne().equals("mountPath")) {
mountPathTime = TimeUUIDUtils.getMicrosTimeFromUUID(column.getName().getTimeUUID());
}
}
assertEquals(1, Math.abs(pathTime - mountPathTime));
}
}
use of com.emc.storageos.db.client.impl.CompositeColumnName in project coprhd-controller by CoprHD.
the class DbConsistencyCheckerHelperTest method testCheckCFIndexing.
@Test
public void testCheckCFIndexing() throws Exception {
ColumnFamily<String, CompositeColumnName> cf = new ColumnFamily<String, CompositeColumnName>("FileShare", StringSerializer.get(), CompositeColumnNameSerializer.get());
ColumnFamily<String, IndexColumnName> indexCF = new ColumnFamily<String, IndexColumnName>("AltIdIndex", StringSerializer.get(), IndexColumnNameSerializer.get());
Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
FileShare testData = new FileShare();
testData.setId(URIUtil.createId(FileShare.class));
testData.setPath("A1");
testData.setMountPath("A2");
getDbClient().createObject(testData);
keyspace.prepareQuery(indexCF).withCql(String.format("delete from \"AltIdIndex\" where key='%s'", "A1")).execute();
CheckResult checkResult = new CheckResult();
helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
assertEquals(1, checkResult.getTotal());
keyspace.prepareQuery(indexCF).withCql(String.format("delete from \"AltIdIndex\" where key='%s'", "A2")).execute();
checkResult = new CheckResult();
helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
assertEquals(2, checkResult.getTotal());
helper = new DbConsistencyCheckerHelper((DbClientImpl) getDbClient()) {
@Override
protected boolean isDataObjectRemoved(Class<? extends DataObject> clazz, String key) {
return true;
}
};
checkResult = new CheckResult();
helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
assertEquals(0, checkResult.getTotal());
testData = new FileShare();
testData.setId(URIUtil.createId(FileShare.class));
testData.setPath("A'A'");
testData.setMountPath("A2");
getDbClient().createObject(testData);
checkResult = new CheckResult();
helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
assertEquals(0, checkResult.getTotal());
}
Aggregations