use of com.emc.storageos.db.client.impl.IndexCleanupList 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);
}
Aggregations