Search in sources :

Example 1 with CqlStatementResult

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);
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) Volume(com.emc.storageos.db.client.model.Volume) IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) CqlStatement(com.netflix.astyanax.cql.CqlStatement) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) CqlStatementResult(com.netflix.astyanax.cql.CqlStatementResult) Test(org.junit.Test)

Example 2 with CqlStatementResult

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);
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) CqlStatement(com.netflix.astyanax.cql.CqlStatement) URI(java.net.URI) CqlStatementResult(com.netflix.astyanax.cql.CqlStatementResult) Test(org.junit.Test)

Example 3 with CqlStatementResult

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);
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) Volume(com.emc.storageos.db.client.model.Volume) IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) CqlStatement(com.netflix.astyanax.cql.CqlStatement) CqlStatementResult(com.netflix.astyanax.cql.CqlStatementResult) Test(org.junit.Test)

Aggregations

DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)3 IndexColumnName (com.emc.storageos.db.client.impl.IndexColumnName)3 Volume (com.emc.storageos.db.client.model.Volume)3 CqlStatement (com.netflix.astyanax.cql.CqlStatement)3 CqlStatementResult (com.netflix.astyanax.cql.CqlStatementResult)3 Test (org.junit.Test)3 CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)2 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)1 URI (java.net.URI)1