Search in sources :

Example 1 with RebuildIndexDuplicatedCFNameMigration

use of com.emc.storageos.db.client.upgrade.callbacks.RebuildIndexDuplicatedCFNameMigration 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));
    }
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) ColumnList(com.netflix.astyanax.model.ColumnList) RebuildIndexDuplicatedCFNameMigration(com.emc.storageos.db.client.upgrade.callbacks.RebuildIndexDuplicatedCFNameMigration) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) FileShare(com.emc.storageos.db.client.model.FileShare) Test(org.junit.Test)

Aggregations

CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)1 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)1 DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)1 FileShare (com.emc.storageos.db.client.model.FileShare)1 RebuildIndexDuplicatedCFNameMigration (com.emc.storageos.db.client.upgrade.callbacks.RebuildIndexDuplicatedCFNameMigration)1 ColumnList (com.netflix.astyanax.model.ColumnList)1 Test (org.junit.Test)1