use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class DbClientTest method testTimeSeriesWithTimestamp.
@Test
public void testTimeSeriesWithTimestamp() throws Exception {
// org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.INFO);
_logger.info("Starting testTimeSeriesWithTimestamp");
final int perThreadCount = 10;
final int numThreads = 5;
final DbClient dbClient = _dbClient;
// write
final Event e = new Event();
e.setEventType("randomstuff");
e.setVirtualPool(URI.create("urn:storageos:VirtualPool:random"));
e.setEventId("abc");
e.setProjectId(URI.create("urn:storageos:Project:abcrandom"));
e.setResourceId(URI.create("urn:storageos:FileShare:random"));
e.setSeverity("REALLY BAD");
e.setUserId(URI.create("urn:storageos:User:foobar"));
e.setTimeInMillis(-1);
// Given time for data points of time series
final DateTime dateTime = new DateTime(2000, 1, 1, 0, 0, DateTimeZone.UTC);
ExecutorService executor = Executors.newFixedThreadPool(numThreads);
long duration = System.currentTimeMillis();
for (int threadIndex = 0; threadIndex < numThreads; threadIndex++) {
final int threadId = threadIndex;
executor.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
for (int index = 0; index < perThreadCount; index++) {
long millis = dateTime.getMillis() + (long) ((perThreadCount) * threadId + index) * 1000;
DateTime time = new DateTime(millis, DateTimeZone.UTC);
dbClient.insertTimeSeries(EventTimeSeries.class, time, e);
}
return null;
}
});
}
executor.shutdown();
Assert.assertTrue(executor.awaitTermination(60, TimeUnit.SECONDS));
duration = System.currentTimeMillis() - duration;
_logger.info("Insertion throughput with batch size {} is {} records per second", 1, (perThreadCount * numThreads) / (duration / 1000f));
// read at default granularity
executor = Executors.newFixedThreadPool(numThreads);
CountDownLatch latch = new CountDownLatch(numThreads * perThreadCount);
DummyQueryResult result = new DummyQueryResult(latch);
_logger.info("Starting query with default granularity");
duration = System.currentTimeMillis();
dbClient.queryTimeSeries(EventTimeSeries.class, dateTime, result, executor);
Assert.assertTrue(latch.await(60, TimeUnit.SECONDS));
duration = System.currentTimeMillis() - duration;
_logger.info("Read throughput(HOUR) is {} records per second", (perThreadCount * numThreads) / (duration / 1000f));
_logger.info("Finished testTimeSeriesWithTimestamp");
}
use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class DbClientTest method testQueryByType.
@Test
public void testQueryByType() {
DbClient dbClient = _dbClient;
List<URI> expected = new ArrayList<URI>();
for (int i = 0; i < 10; i++) {
AuthnProvider provider = new AuthnProvider();
provider.setId(URIUtil.createId(AuthnProvider.class));
provider.setLabel("provider" + i);
dbClient.createObject(provider);
expected.add(provider.getId());
}
List<AuthnProvider> providerList = new ArrayList<AuthnProvider>();
for (int i = 10; i < 120; i++) {
AuthnProvider provider = new AuthnProvider();
provider.setId(URIUtil.createId(AuthnProvider.class));
provider.setLabel("provider" + i);
providerList.add(provider);
expected.add(provider.getId());
providerList.add(provider);
}
dbClient.createObject(providerList);
List<URI> match = new ArrayList<URI>(expected);
List<URI> uris = dbClient.queryByType(AuthnProvider.class, true);
Iterator<URI> it = uris.iterator();
Assert.assertTrue(it.hasNext());
int apCnt = 0;
while (it.hasNext()) {
apCnt++;
URI uri = it.next();
Assert.assertTrue(match.contains(uri));
match.remove(uri);
}
Assert.assertEquals(apCnt, 120);
Assert.assertEquals(match.size(), 0);
// query with active flag
List<URI> activeOnly = new ArrayList<URI>(expected);
for (int i = 0; i < 5; i++) {
AuthnProvider provider = new AuthnProvider();
provider.setId(expected.get(i));
provider.setInactive(true);
dbClient.updateAndReindexObject(provider);
activeOnly.remove(expected.get(i));
}
// all query
match = new ArrayList<URI>(expected);
uris = dbClient.queryByType(AuthnProvider.class, false);
it = uris.iterator();
Assert.assertTrue(it.hasNext());
while (it.hasNext()) {
URI uri = it.next();
Assert.assertTrue(String.format("URI %s is not contained in match (%d)", uri.toString(), match.size()), match.contains(uri));
match.remove(uri);
}
Assert.assertEquals(0, match.size());
// active only query - with mixed active/inactive
uris = dbClient.queryByType(AuthnProvider.class, true);
it = uris.iterator();
Assert.assertTrue(it.hasNext());
while (it.hasNext()) {
URI uri = it.next();
Assert.assertTrue(activeOnly.contains(uri));
activeOnly.remove(uri);
}
Assert.assertEquals(0, activeOnly.size());
}
use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class DbClientTest method testNamedURI.
@Test
public void testNamedURI() throws Exception {
_logger.info("Starting named uri test");
int objCount = 1000;
String prefix = "99";
URI target = URIUtil.createId(TenantOrg.class);
Set<URI> expectedResult = new HashSet<URI>();
DbClient dbClient = _dbClient;
for (int index = 0; index < objCount; index++) {
Project pj = new Project();
pj.setId(URIUtil.createId(Project.class));
String label = String.format("%1$d :/#$#@$\\: Test Label", index);
pj.setLabel(label);
pj.setTenantOrg(new NamedURI(target, label));
if (label.startsWith(prefix)) {
expectedResult.add(pj.getId());
}
dbClient.persistObject(pj);
}
List<URI> result = dbClient.queryByConstraint(ContainmentPrefixConstraint.Factory.getProjectUnderTenantConstraint(target, prefix));
Assert.assertEquals(result.size(), expectedResult.size());
for (int i = 0; i < result.size(); i++) {
Assert.assertTrue(expectedResult.contains(result.get(i)));
}
String newPrefix = "xxx";
Iterator<URI> it = expectedResult.iterator();
while (it.hasNext()) {
Project pj = dbClient.queryObject(Project.class, it.next());
pj.setLabel(newPrefix + pj.getLabel());
pj.setTenantOrg(new NamedURI(pj.getTenantOrg().getURI(), pj.getLabel()));
dbClient.persistObject(pj);
pj = dbClient.queryObject(Project.class, pj.getId());
}
result = dbClient.queryByConstraint(ContainmentPrefixConstraint.Factory.getProjectUnderTenantConstraint(target, newPrefix));
Assert.assertEquals(result.size(), expectedResult.size());
for (int i = 0; i < result.size(); i++) {
Assert.assertTrue(expectedResult.contains(result.get(i)));
}
result = dbClient.queryByConstraint(ContainmentPrefixConstraint.Factory.getProjectUnderTenantConstraint(target, prefix));
Assert.assertEquals(result.size(), 0);
_logger.info("Done with named uri test");
}
use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class DbClientTest method testCfWithMutipleRelationIndex.
@Test
public void testCfWithMutipleRelationIndex() {
_logger.info("Starting testCompareIndexes");
DbClient dbClient = _dbClient;
URI varrayId1 = URIUtil.createId(VirtualArray.class);
VirtualArray varray1 = new VirtualArray();
varray1.setId(varrayId1);
varray1.setLabel("varray1");
dbClient.createObject(varray1);
Network nw1 = new Network();
nw1.setId(URIUtil.createId(Network.class));
nw1.setLabel("networkObj");
StringSet varrayStrSet1 = new StringSet();
varrayStrSet1.add(varrayId1.toString());
nw1.setAssignedVirtualArrays(varrayStrSet1);
dbClient.createObject(nw1);
List<Network> assignedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId1, Network.class, "assignedVirtualArrays");
Assert.assertTrue(assignedNetworks.iterator().hasNext());
Assert.assertEquals(assignedNetworks.size(), 1);
List<Network> connectedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId1, Network.class, "connectedVirtualArrays");
Assert.assertFalse(connectedNetworks.iterator().hasNext());
URI varrayId2 = URIUtil.createId(VirtualArray.class);
VirtualArray varray2 = new VirtualArray();
varray2.setId(varrayId2);
varray2.setLabel("varray2");
dbClient.createObject(varray2);
StringSet varrayStrSet2 = new StringSet();
varrayStrSet2.add(varrayId1.toString());
varrayStrSet2.add(varrayId2.toString());
nw1.setConnectedVirtualArrays(varrayStrSet2);
dbClient.persistObject(nw1);
assignedNetworks.clear();
assignedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId1, Network.class, "assignedVirtualArrays");
Assert.assertTrue(assignedNetworks.iterator().hasNext());
Assert.assertEquals(assignedNetworks.size(), 1);
connectedNetworks.clear();
connectedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId2, Network.class, "connectedVirtualArrays");
Assert.assertTrue(connectedNetworks.iterator().hasNext());
Assert.assertEquals(connectedNetworks.size(), 1);
connectedNetworks.clear();
connectedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId1, Network.class, "connectedVirtualArrays");
Assert.assertTrue(connectedNetworks.iterator().hasNext());
Assert.assertEquals(connectedNetworks.size(), 1);
assignedNetworks.clear();
assignedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId2, Network.class, "assignedVirtualArrays");
Assert.assertFalse(assignedNetworks.iterator().hasNext());
}
use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class DbClientTest method testTagIndex.
@Test
public void testTagIndex() throws Exception {
_logger.info("Starting testTagIndex");
final int objCount = 1000;
final String prefix = "55";
Set<URI> expectedResult = new HashSet<URI>();
URI tenant = URIUtil.createId(TenantOrg.class);
DbClient dbClient = _dbClient;
for (int index = 0; index < objCount; index++) {
FileShare fs = new FileShare();
fs.setId(URIUtil.createId(FileShare.class));
fs.setLabel("foobar");
String tag = String.format("%1$d - test label", index);
if (tag.startsWith(prefix)) {
expectedResult.add(fs.getId());
}
ScopedLabelSet tagSet = new ScopedLabelSet();
tagSet.add(new ScopedLabel(tenant.toString(), tag));
fs.setTag(tagSet);
dbClient.persistObject(fs);
}
List<URI> hits = dbClient.queryByConstraint(PrefixConstraint.Factory.getTagsPrefixConstraint(FileShare.class, prefix, null));
Assert.assertEquals(hits.size(), expectedResult.size());
for (int i = 0; i < hits.size(); i++) {
Assert.assertTrue(expectedResult.contains(hits.get(i)));
}
hits = dbClient.queryByConstraint(PrefixConstraint.Factory.getTagsPrefixConstraint(FileShare.class, prefix, tenant));
Assert.assertEquals(hits.size(), expectedResult.size());
for (int i = 0; i < hits.size(); i++) {
Assert.assertTrue(expectedResult.contains(hits.get(i)));
}
hits = dbClient.queryByConstraint(PrefixConstraint.Factory.getTagsPrefixConstraint(FileShare.class, "foobar", tenant));
Assert.assertEquals(hits.size(), 0);
}
Aggregations