use of com.netflix.astyanax.cql.CqlStatementResult in project coprhd-controller by CoprHD.
the class RowMutationTest method insertRecordAndIndexColumnWithError.
@Test
public void insertRecordAndIndexColumnWithError() 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()), "");
// insert error column
ColumnListMutation<CompositeColumnName> no_columnList = rowMutator.getRecordColumnList(noExistCF, rowKey);
no_columnList.putColumn(new CompositeColumnName("test"), 20);
try {
rowMutator.execute();
Assert.fail();
} catch (Exception e) {
// expected exception
}
// no volume should be created
Volume volume = (Volume) this.getDbClient().queryObject(URI.create(rowKey));
Assert.assertNull(volume);
// no index should be created
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(), 0);
}
use of com.netflix.astyanax.cql.CqlStatementResult 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.netflix.astyanax.cql.CqlStatementResult 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);
}
Aggregations