use of com.emc.storageos.db.client.impl.IndexColumnName in project coprhd-controller by CoprHD.
the class PersistingChangesTest method getIndexRecordCount.
private int getIndexRecordCount(String fieldName) throws ConnectionException {
Keyspace keyspace = ((DbClientTest.DbClientImplUnitTester) dbClient).getLocalContext().getKeyspace();
DataObjectType doType = TypeMap.getDoType(Volume.class);
ColumnField field = doType.getColumnField(fieldName);
ColumnFamilyQuery<String, IndexColumnName> query = keyspace.prepareQuery(field.getIndexCF());
OperationResult<Rows<String, IndexColumnName>> result = query.getAllRows().execute();
int count = 0;
for (Row<String, IndexColumnName> row : result.getResult()) {
_log.debug("{}, RowKey={}, Columns Size={}", ++count, row.getKey(), row.getColumns().size());
for (Column<IndexColumnName> column : row.getColumns()) {
_log.debug("\t, Column Name={}, String Value={}.", column.getName(), column.getStringValue());
}
}
return count;
}
use of com.emc.storageos.db.client.impl.IndexColumnName in project coprhd-controller by CoprHD.
the class RowMutationTest method insertDataObject.
@Test
public void insertDataObject() throws ConnectionException {
String prefix = "AA";
Volume volume = new Volume();
URI id = URIUtil.createId(Volume.class);
URI pool = URIUtil.createId(StoragePool.class);
volume.setId(id);
volume.setLabel(prefix + "volume");
volume.setPool(pool);
volume.setNativeGuid(prefix + "native_guid-2");
volume.setNativeId(prefix + "native_id-2");
volume.setCompositionType(prefix + "compositionType");
volume.setInactive(false);
volume.setAllocatedCapacity(1000L);
volume.setProvisionedCapacity(2000L);
this.getDbClient().updateObject(volume);
Volume target = (Volume) this.getDbClient().queryObject(id);
Assert.assertNotNull(target);
Assert.assertEquals(target.getLabel(), volume.getLabel());
Assert.assertEquals(target.getPool(), volume.getPool());
Assert.assertEquals(target.getNativeGuid(), volume.getNativeGuid());
Assert.assertEquals(target.getNativeId(), volume.getNativeId());
Assert.assertEquals(target.getCompositionType(), volume.getCompositionType());
Assert.assertEquals(target.getAllocatedCapacity(), volume.getAllocatedCapacity());
Assert.assertEquals(target.getProvisionedCapacity(), volume.getProvisionedCapacity());
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'", prefix.toLowerCase(), volume.getLabel().toLowerCase(), volume.getLabel(), volume.getId().toString());
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.IndexColumnName 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.IndexColumnName 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