use of org.apache.geode.cache.query.data.PortfolioPdx in project geode by apache.
the class PutAllWithIndexPerfDUnitTest method testPutAllWithIndexes.
@Ignore("TODO: test is disabled")
@Test
public void testPutAllWithIndexes() {
final String name = "testRegion";
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final int numberOfEntries = 10000;
// Start server
vm0.invoke(new CacheSerializableRunnable("Create Bridge Server") {
public void run2() throws CacheException {
Properties config = new Properties();
config.put(LOCATORS, "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]");
Cache cache = new CacheFactory(config).create();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
cache.createRegionFactory(factory.create()).create(name);
try {
startBridgeServer(0, false);
} catch (Exception ex) {
Assert.fail("While starting CacheServer", ex);
}
// Create Index on empty region
try {
cache.getQueryService().createIndex("idIndex", "ID", "/" + name);
} catch (Exception e) {
Assert.fail("index creation failed", e);
}
}
});
// Create client region
final int port = vm0.invoke(() -> PutAllWithIndexPerfDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
vm1.invoke(new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
Properties config = new Properties();
config.setProperty(MCAST_PORT, "0");
ClientCache cache = new ClientCacheFactory().addPoolServer(host0, port).create();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(name);
}
});
vm1.invoke(new CacheSerializableRunnable("putAll() test") {
@Override
public void run2() throws CacheException {
Region exampleRegion = ClientCacheFactory.getAnyInstance().getRegion(name);
Map warmupMap = new HashMap();
Map data = new HashMap();
for (int i = 0; i < 10000; i++) {
Object p = new PortfolioPdx(i);
if (i < 1000)
warmupMap.put(i, p);
data.put(i, p);
}
for (int i = 0; i < 10; i++) {
exampleRegion.putAll(warmupMap);
}
long start = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
exampleRegion.putAll(data);
}
long end = System.currentTimeMillis();
timeWithoutStructTypeIndex = ((end - start) / 10);
System.out.println("Total putall time for 10000 objects is: " + ((end - start) / 10) + "ms");
}
});
vm0.invoke(new CacheSerializableRunnable("Remove Index and create new one") {
@Override
public void run2() throws CacheException {
try {
Cache cache = CacheFactory.getAnyInstance();
cache.getQueryService().removeIndexes();
cache.getRegion(name).clear();
cache.getQueryService().createIndex("idIndex", "p.ID", "/" + name + " p");
} catch (Exception e) {
Assert.fail("index creation failed", e);
}
}
});
vm1.invoke(new CacheSerializableRunnable("putAll() test") {
@Override
public void run2() throws CacheException {
Region exampleRegion = ClientCacheFactory.getAnyInstance().getRegion(name);
exampleRegion.clear();
Map warmupMap = new HashMap();
Map data = new HashMap();
for (int i = 0; i < 10000; i++) {
Object p = new PortfolioPdx(i);
if (i < 1000)
warmupMap.put(i, p);
data.put(i, p);
}
for (int i = 0; i < 10; i++) {
exampleRegion.putAll(warmupMap);
}
long start = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
exampleRegion.putAll(data);
}
long end = System.currentTimeMillis();
timeWithStructTypeIndex = ((end - start) / 10);
System.out.println("Total putall time for 10000 objects is: " + ((end - start) / 10) + "ms");
}
});
if (timeWithoutStructTypeIndex > timeWithStructTypeIndex) {
fail("putAll took more time without struct type index than simple index");
}
}
Aggregations