Search in sources :

Example 1 with IndexCleaner

use of com.emc.storageos.db.client.impl.IndexCleaner in project coprhd-controller by CoprHD.

the class PersistingChangesTest method testCleanupSoftReference.

@Test
public void testCleanupSoftReference() throws ConnectionException {
    Volume volume = new Volume();
    URI id = URIUtil.createId(Volume.class);
    URI pool = URIUtil.createId(StoragePool.class);
    volume.setId(id);
    volume.setLabel("origin");
    volume.setPool(pool);
    volume.setNativeGuid("native_guid");
    volume.setNativeId("native_id");
    volume.setCompositionType("compositionType");
    volume.setInactive(false);
    volume.setAllocatedCapacity(1000L);
    volume.setProvisionedCapacity(2000L);
    dbClient.updateObject(volume);
    // Search the label index directly
    String labelFieldName = "label";
    int labelCount = getIndexRecordCount(labelFieldName);
    // By default, label index contains one record for VirtualDataCenter
    Assert.assertEquals(2, labelCount);
    List<URI> volumes = dbClient.queryByType(Volume.class, true);
    int size = 0;
    for (URI uri : volumes) {
        Volume entry = dbClient.queryObject(Volume.class, uri);
        _log.info("{}, URI={}, Label={}", ++size, uri, entry.getLabel());
        Assert.assertEquals("origin", entry.getLabel());
    }
    Assert.assertEquals(1, size);
    _log.info("\nStart to update with new label");
    // Mock warning when listToCleanRef is null in indexCleaner
    this.dbClient = super.getDbClient(new DbClientTest.DbClientImplUnitTester() {

        @Override
        public synchronized void start() {
            super.start();
            _indexCleaner = new IndexCleaner() {

                @Override
                public void cleanIndex(RowMutator mutator, DataObjectType doType, SoftReference<IndexCleanupList> listToCleanRef) {
                    listToCleanRef.clear();
                    super.cleanIndex(mutator, doType, listToCleanRef);
                }
            };
        }
    });
    volume = dbClient.queryObject(Volume.class, id);
    volume.setLabel("new");
    dbClient.updateObject(volume);
    // Search the label index directly
    labelCount = getIndexRecordCount(labelFieldName);
    // We mocked indexCleaner, so that old label index couldn't be removed, still in DB
    Assert.assertEquals(3, labelCount);
    volumes = dbClient.queryByType(Volume.class, true);
    size = 0;
    for (URI uri : volumes) {
        Volume entry = dbClient.queryObject(Volume.class, uri);
        _log.info("{}, URI={}, Label={}", ++size, uri, entry.getLabel());
        Assert.assertEquals("new", entry.getLabel());
    }
    Assert.assertEquals(1, size);
    // Remove the object
    _log.info("\nStart to remove volume");
    this.dbClient = super.getDbClient(new DbClientTest.DbClientImplUnitTester());
    volume = dbClient.queryObject(Volume.class, id);
    dbClient.removeObject(volume);
    // Search the label index directly
    labelCount = getIndexRecordCount(labelFieldName);
    // All the label index related to volume should be removed.
    Assert.assertEquals(1, labelCount);
    volumes = dbClient.queryByType(Volume.class, true);
    size = 0;
    for (URI uri : volumes) {
        Volume entry = dbClient.queryObject(Volume.class, uri);
        _log.info("{}, URI={}, Label={}", ++size, uri, entry.getLabel());
    }
    Assert.assertEquals(0, size);
}
Also used : IndexCleanupList(com.emc.storageos.db.client.impl.IndexCleanupList) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) IndexCleaner(com.emc.storageos.db.client.impl.IndexCleaner) URI(java.net.URI) RowMutator(com.emc.storageos.db.client.impl.RowMutator) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) com.emc.storageos.db.client.constraint(com.emc.storageos.db.client.constraint) Test(org.junit.Test) DbClientTest(com.emc.storageos.db.server.DbClientTest)

Aggregations

com.emc.storageos.db.client.constraint (com.emc.storageos.db.client.constraint)1 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)1 IndexCleaner (com.emc.storageos.db.client.impl.IndexCleaner)1 IndexCleanupList (com.emc.storageos.db.client.impl.IndexCleanupList)1 RowMutator (com.emc.storageos.db.client.impl.RowMutator)1 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)1 DbClientTest (com.emc.storageos.db.server.DbClientTest)1 URI (java.net.URI)1 Test (org.junit.Test)1