use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class ConcurrentIndexOperationsOnOverflowRegionDUnitTest method testAsyncIndexInitDuringEntryDestroyAndQueryOnRR.
// GEODE-1828
@Category(FlakyTest.class)
@Test
public void testAsyncIndexInitDuringEntryDestroyAndQueryOnRR() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
hooked = false;
name = "PartionedPortfoliosPR";
// Create Overflow Persistent Partition Region
vm0.invoke(new CacheSerializableRunnable("Create local region with synchronous index maintenance") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region partitionRegion = null;
IndexManager.testHook = null;
try {
DiskStore ds = cache.findDiskStore("disk");
if (ds == null) {
ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
}
AttributesFactory attr = new AttributesFactory();
attr.setValueConstraint(PortfolioData.class);
attr.setIndexMaintenanceSynchronous(true);
EvictionAttributesImpl evicAttr = new EvictionAttributesImpl().setAction(EvictionAction.OVERFLOW_TO_DISK);
evicAttr.setAlgorithm(EvictionAlgorithm.LRU_ENTRY).setMaximum(1);
attr.setEvictionAttributes(evicAttr);
attr.setDataPolicy(DataPolicy.REPLICATE);
// attr.setPartitionAttributes(new
// PartitionAttributesFactory().setTotalNumBuckets(1).create());
attr.setDiskStoreName("disk");
RegionFactory regionFactory = cache.createRegionFactory(attr.create());
partitionRegion = regionFactory.create(name);
} catch (IllegalStateException ex) {
LogWriterUtils.getLogWriter().warning("Creation caught IllegalStateException", ex);
}
assertNotNull("Region " + name + " not in cache", cache.getRegion(name));
assertNotNull("Region ref null", partitionRegion);
assertTrue("Region ref claims to be destroyed", !partitionRegion.isDestroyed());
// Create Indexes
try {
Index index = cache.getQueryService().createIndex("statusIndex", "p.ID", "/" + name + " p");
assertNotNull(index);
} catch (Exception e1) {
e1.printStackTrace();
fail("Index creation failed");
}
}
});
// Start changing the value in Region which should turn into a deadlock if the fix is not there
AsyncInvocation asyncInv1 = vm0.invokeAsync(new CacheSerializableRunnable("Change value in region") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
// Do a put in region.
Region r = getCache().getRegion(name);
for (int i = 0; i < 100; i++) {
r.put(i, new PortfolioData(i));
}
assertNull(IndexManager.testHook);
IndexManager.testHook = new IndexManagerTestHook();
// Destroy one of the values.
getCache().getLogger().fine("Destroying the value");
r.destroy(1);
IndexManager.testHook = null;
}
});
AsyncInvocation asyncInv2 = vm0.invokeAsync(new CacheSerializableRunnable("Run query on region") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Query statusQuery = getCache().getQueryService().newQuery("select * from /" + name + " p where p.ID > -1");
while (!hooked) {
Wait.pause(100);
}
try {
getCache().getLogger().fine("Querying the region");
SelectResults results = (SelectResults) statusQuery.execute();
assertEquals(100, results.size());
} catch (Exception e) {
e.printStackTrace();
}
}
});
// If we take more than 30 seconds then its a deadlock.
ThreadUtils.join(asyncInv2, 30 * 1000);
ThreadUtils.join(asyncInv1, 30 * 1000);
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class ConcurrentIndexOperationsOnOverflowRegionDUnitTest method testAsyncIndexInitDuringEntryDestroyAndQueryOnOnNonOverflowPR.
/**
*
*/
@Test
public void testAsyncIndexInitDuringEntryDestroyAndQueryOnOnNonOverflowPR() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
hooked = false;
name = "PartionedPortfoliosPR";
// Create Overflow Persistent Partition Region
vm0.invoke(new CacheSerializableRunnable("Create local region with synchronous index maintenance") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region partitionRegion = null;
IndexManager.testHook = null;
try {
AttributesFactory attr = new AttributesFactory();
attr.setValueConstraint(PortfolioData.class);
attr.setIndexMaintenanceSynchronous(true);
attr.setDataPolicy(DataPolicy.PARTITION);
attr.setPartitionAttributes(new PartitionAttributesFactory().setTotalNumBuckets(1).create());
RegionFactory regionFactory = cache.createRegionFactory(attr.create());
partitionRegion = regionFactory.create(name);
} catch (IllegalStateException ex) {
LogWriterUtils.getLogWriter().warning("Creation caught IllegalStateException", ex);
}
assertNotNull("Region " + name + " not in cache", cache.getRegion(name));
assertNotNull("Region ref null", partitionRegion);
assertTrue("Region ref claims to be destroyed", !partitionRegion.isDestroyed());
// Create Indexes
try {
Index index = cache.getQueryService().createIndex("statusIndex", "p.ID", "/" + name + " p");
assertNotNull(index);
} catch (Exception e1) {
e1.printStackTrace();
fail("Index creation failed");
}
}
});
// Start changing the value in Region which should turn into a deadlock if the fix is not there
AsyncInvocation asyncInv1 = vm0.invokeAsync(new CacheSerializableRunnable("Change value in region") {
@Override
public void run2() throws CacheException {
// Do a put in region.
Region r = getCache().getRegion(name);
for (int i = 0; i < 100; i++) {
r.put(i, new PortfolioData(i));
}
assertNull(IndexManager.testHook);
IndexManager.testHook = new IndexManagerNoWaitTestHook();
// Destroy one of the values.
getCache().getLogger().fine("Destroying the value");
r.destroy(1);
IndexManager.testHook = null;
}
});
AsyncInvocation asyncInv2 = vm0.invokeAsync(new CacheSerializableRunnable("Run query on region") {
@Override
public void run2() throws CacheException {
Query statusQuery = getCache().getQueryService().newQuery("select * from /" + name + " p where p.ID > -1");
while (!hooked) {
Wait.pause(10);
}
try {
getCache().getLogger().fine("Querying the region");
SelectResults results = (SelectResults) statusQuery.execute();
assertEquals(100, results.size());
} catch (Exception e) {
e.printStackTrace();
}
}
});
// If we take more than 30 seconds then its a deadlock.
ThreadUtils.join(asyncInv2, 30 * 1000);
ThreadUtils.join(asyncInv1, 30 * 1000);
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class SSLNoClientAuthDUnitTest method setUpServerVM.
@SuppressWarnings("rawtypes")
public void setUpServerVM(boolean cacheServerSslenabled) throws Exception {
Properties gemFireProps = new Properties();
String cacheServerSslprotocols = "any";
String cacheServerSslciphers = "any";
boolean cacheServerSslRequireAuth = false;
gemFireProps.put(SERVER_SSL_ENABLED, String.valueOf(cacheServerSslenabled));
gemFireProps.put(SERVER_SSL_PROTOCOLS, cacheServerSslprotocols);
gemFireProps.put(SERVER_SSL_CIPHERS, cacheServerSslciphers);
gemFireProps.put(SERVER_SSL_REQUIRE_AUTHENTICATION, String.valueOf(cacheServerSslRequireAuth));
String keyStore = TestUtil.getResourcePath(SSLNoClientAuthDUnitTest.class, DEFAULT_STORE);
String trustStore = TestUtil.getResourcePath(SSLNoClientAuthDUnitTest.class, DEFAULT_STORE);
gemFireProps.put(SERVER_SSL_KEYSTORE_TYPE, "jks");
gemFireProps.put(SERVER_SSL_KEYSTORE, keyStore);
gemFireProps.put(SERVER_SSL_KEYSTORE_PASSWORD, "password");
gemFireProps.put(SERVER_SSL_TRUSTSTORE, trustStore);
gemFireProps.put(SERVER_SSL_TRUSTSTORE_PASSWORD, "password");
StringWriter sw = new StringWriter();
PrintWriter writer = new PrintWriter(sw);
gemFireProps.list(writer);
System.out.println("Starting cacheserver ds with following properties \n" + sw);
createCache(gemFireProps);
RegionFactory factory = cache.createRegionFactory(RegionShortcut.REPLICATE);
Region r = factory.create("serverRegion");
r.put("serverkey", "servervalue");
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class InitializeIndexEntryDestroyQueryDUnitTest method testConcurrentRemoveIndexAndQueryOnPR.
@Test
public void testConcurrentRemoveIndexAndQueryOnPR() {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
setCacheInVMs(vm0);
name = "PartionedPortfoliosPR";
// Create Local Region
vm0.invoke(new CacheSerializableRunnable("Create local region with asynchronous index maintenance") {
@Override
public void run2() throws CacheException {
Cache cache = getCache();
Region partitionRegion = null;
try {
AttributesFactory attr = new AttributesFactory();
attr.setValueConstraint(PortfolioData.class);
attr.setIndexMaintenanceSynchronous(false);
attr.setPartitionAttributes(new PartitionAttributesFactory().create());
RegionFactory regionFactory = cache.createRegionFactory(attr.create());
partitionRegion = regionFactory.create(name);
} catch (IllegalStateException ex) {
LogWriterUtils.getLogWriter().warning("Creation caught IllegalStateException", ex);
}
assertNotNull("Region " + name + " not in cache", cache.getRegion(name));
assertNotNull("Region ref null", partitionRegion);
assertTrue("Region ref claims to be destroyed", !partitionRegion.isDestroyed());
}
});
final PortfolioData[] portfolio = createPortfolioData(cnt, cntDest);
// Putting the data into the PR's created
vm0.invoke(PRQHelp.getCacheSerializableRunnableForPRPuts(name, portfolio, cnt, cntDest));
vm0.invoke(new CacheSerializableRunnable("Create Index") {
@Override
public void run2() throws CacheException {
// Create Index first to go in hook.
Cache cache = getCache();
Index sindex = null;
Index iindex = null;
Index pkindex = null;
try {
sindex = cache.getQueryService().createIndex("statusIndex", "p.status", "/" + name + " p");
iindex = cache.getQueryService().createIndex("idIndex", "p.ID", "/" + name + " p");
pkindex = cache.getQueryService().createIndex("pkidIndex", "p.pk", "/" + name + " p");
} catch (Exception e1) {
e1.printStackTrace();
fail("Index creation failed");
}
assertNotNull(sindex);
assertNotNull(iindex);
assertNotNull(pkindex);
}
});
vm0.invoke(new CacheSerializableRunnable("Run query on region") {
@Override
public void run2() throws CacheException {
// Do a put in region.
Query query = getCache().getQueryService().newQuery("select * from /" + name + " p where p.status = 'active' and p.ID > 0 and p.pk != ' ' ");
// Now run the query
SelectResults results = null;
for (int i = 0; i < 10; i++) {
try {
getCache().getLogger().fine("Querying the region with " + query);
results = (SelectResults) query.execute();
} catch (Exception e) {
Assert.fail("Query: " + query + " execution failed with exception", e);
}
for (Object obj : results) {
if (obj instanceof Undefined) {
fail("Found an undefined element" + Arrays.toString(results.toArray()));
}
}
}
}
});
vm0.invoke(new CacheSerializableRunnable("Create Index") {
@Override
public void run2() throws CacheException {
Region r = getCache().getRegion(name);
// Create Index first to go in hook.
getCache().getQueryService().removeIndexes(r);
}
});
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class MultiVMRegionTestCase method createRegionWithAttribute.
protected void createRegionWithAttribute(VM vm, final String name, final boolean syncDiskWrite) {
SerializableRunnable createRegion = new SerializableRunnable("Create Region") {
@Override
public void run() {
try {
RegionFactory f = getCache().createRegionFactory(getRegionAttributes());
f.setDiskSynchronous(syncDiskWrite);
CCRegion = (LocalRegion) f.create(name);
} catch (CacheException ex) {
fail("While creating region", ex);
}
}
};
vm.invoke(createRegion);
}
Aggregations