use of org.apache.geode.internal.cache.ProxyBucketRegion in project geode by apache.
the class ParallelQueueRemovalMessageJUnitTest method createBucketRegionQueue.
private void createBucketRegionQueue() {
// Create InternalRegionArguments
InternalRegionArguments ira = new InternalRegionArguments();
ira.setPartitionedRegion(this.queueRegion);
ira.setPartitionedRegionBucketRedundancy(1);
BucketAdvisor ba = mock(BucketAdvisor.class);
ira.setBucketAdvisor(ba);
InternalRegionArguments pbrIra = new InternalRegionArguments();
RegionAdvisor ra = mock(RegionAdvisor.class);
when(ra.getPartitionedRegion()).thenReturn(this.queueRegion);
pbrIra.setPartitionedRegionAdvisor(ra);
PartitionAttributes pa = mock(PartitionAttributes.class);
when(this.queueRegion.getPartitionAttributes()).thenReturn(pa);
when(this.queueRegion.getBucketName(eq(BUCKET_ID))).thenAnswer(new Answer<String>() {
@Override
public String answer(final InvocationOnMock invocation) throws Throwable {
return PartitionedRegionHelper.getBucketName(queueRegion.getFullPath(), BUCKET_ID);
}
});
when(this.queueRegion.getDataPolicy()).thenReturn(DataPolicy.PARTITION);
when(pa.getColocatedWith()).thenReturn(null);
// classes cannot be mocked
ProxyBucketRegion pbr = new ProxyBucketRegion(BUCKET_ID, this.queueRegion, pbrIra);
when(ba.getProxyBucketRegion()).thenReturn(pbr);
// Create RegionAttributes
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(100, null, EvictionAction.OVERFLOW_TO_DISK));
RegionAttributes attributes = factory.create();
// Create BucketRegionQueue
BucketRegionQueue realBucketRegionQueue = new BucketRegionQueue(this.queueRegion.getBucketName(BUCKET_ID), attributes, this.rootRegion, this.cache, ira);
this.bucketRegionQueue = spy(realBucketRegionQueue);
// (this.queueRegion.getBucketName(BUCKET_ID), attributes, this.rootRegion, this.cache, ira);
EntryEventImpl entryEvent = EntryEventImpl.create(this.bucketRegionQueue, Operation.DESTROY, mock(EventID.class), "value", null, false, mock(DistributedMember.class));
doReturn(entryEvent).when(this.bucketRegionQueue).newDestroyEntryEvent(any(), any());
// when(this.bucketRegionQueue.newDestroyEntryEvent(any(), any())).thenReturn();
this.bucketRegionQueueHelper = new BucketRegionQueueHelper(this.cache, this.queueRegion, this.bucketRegionQueue);
}
use of org.apache.geode.internal.cache.ProxyBucketRegion in project geode by apache.
the class MembershipFlushRequest method process.
@Override
protected void process(DistributionManager dm) {
int initLevel = LocalRegion.ANY_INIT;
int oldLevel = LocalRegion.setThreadInitLevelRequirement(initLevel);
ReplyException exception = null;
try {
// get the region from the path, but do NOT wait on initialization,
// otherwise we could have a distributed deadlock
Cache cache = CacheFactory.getInstance(dm.getSystem());
PartitionedRegion region = (PartitionedRegion) cache.getRegion(this.regionPath);
if (region != null && region.getRegionAdvisor().isInitialized()) {
ProxyBucketRegion[] proxyBuckets = region.getRegionAdvisor().getProxyBucketArray();
// buckets are null if initPRInternals is still not complete
if (proxyBuckets != null) {
for (ProxyBucketRegion bucket : proxyBuckets) {
final BucketPersistenceAdvisor persistenceAdvisor = bucket.getPersistenceAdvisor();
if (persistenceAdvisor != null) {
persistenceAdvisor.flushMembershipChanges();
}
}
}
}
} catch (RegionDestroyedException e) {
// ignore
} catch (CancelException e) {
// ignore
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
} catch (Throwable t) {
SystemFailure.checkFailure();
exception = new ReplyException(t);
} finally {
LocalRegion.setThreadInitLevelRequirement(oldLevel);
ReplyMessage replyMsg = new ReplyMessage();
replyMsg.setRecipient(getSender());
replyMsg.setProcessorId(processorId);
if (exception != null) {
replyMsg.setException(exception);
}
dm.putOutgoing(replyMsg);
}
}
use of org.apache.geode.internal.cache.ProxyBucketRegion in project geode by apache.
the class MemoryThresholdsOffHeapDUnitTest method testPRLoadRejection.
/**
* Test that a Partitioned Region loader invocation is rejected if the VM with the bucket is in a
* critical state.
*/
// GEODE-551: waitForCriterion, memory sensitive
@Category(FlakyTest.class)
@Test
public void testPRLoadRejection() throws Exception {
final Host host = Host.getHost(0);
final VM accessor = host.getVM(1);
final VM ds1 = host.getVM(2);
final String rName = getUniqueName();
// Make sure the desired VMs will have a fresh DS. TODO: convert these from AsyncInvocation to
// invoke
AsyncInvocation d0 = accessor.invokeAsync(() -> disconnectFromDS());
AsyncInvocation d1 = ds1.invokeAsync(() -> disconnectFromDS());
d0.join();
assertFalse(d0.exceptionOccurred());
d1.join();
assertFalse(d1.exceptionOccurred());
CacheSerializableRunnable establishConnectivity = new CacheSerializableRunnable("establishcConnectivity") {
@Override
public void run2() throws CacheException {
getSystem();
}
};
ds1.invoke(establishConnectivity);
accessor.invoke(establishConnectivity);
ds1.invoke(createPR(rName, false));
accessor.invoke(createPR(rName, true));
final AtomicInteger expectedInvocations = new AtomicInteger(0);
Integer ex = (Integer) accessor.invoke(new SerializableCallable("Invoke loader from accessor, non-critical") {
public Object call() throws Exception {
Region<Integer, String> r = getCache().getRegion(rName);
Integer k = new Integer(1);
Integer expectedInvocations0 = new Integer(expectedInvocations.getAndIncrement());
// should load for new key
assertEquals(k.toString(), r.get(k, expectedInvocations0));
assertTrue(r.containsKey(k));
Integer expectedInvocations1 = new Integer(expectedInvocations.get());
// no load
assertEquals(k.toString(), r.get(k, expectedInvocations1));
// no load
assertEquals(k.toString(), r.get(k, expectedInvocations1));
return expectedInvocations1;
}
});
expectedInvocations.set(ex.intValue());
ex = (Integer) ds1.invoke(new SerializableCallable("Invoke loader from datastore, non-critical") {
public Object call() throws Exception {
Region<Integer, String> r = getCache().getRegion(rName);
Integer k = new Integer(2);
Integer expectedInvocations1 = new Integer(expectedInvocations.getAndIncrement());
// should load for new key
assertEquals(k.toString(), r.get(k, expectedInvocations1));
assertTrue(r.containsKey(k));
Integer expectedInvocations2 = new Integer(expectedInvocations.get());
// no load
assertEquals(k.toString(), r.get(k, expectedInvocations2));
// no load
assertEquals(k.toString(), r.get(k, expectedInvocations2));
String oldVal = r.remove(k);
assertFalse(r.containsKey(k));
assertEquals(k.toString(), oldVal);
return expectedInvocations2;
}
});
expectedInvocations.set(ex.intValue());
accessor.invoke(addExpectedException);
ds1.invoke(addExpectedException);
ex = (Integer) ds1.invoke(new SerializableCallable("Set critical state, assert local load behavior") {
public Object call() throws Exception {
final OffHeapMemoryMonitor ohmm = ((InternalResourceManager) getCache().getResourceManager()).getOffHeapMonitor();
final PartitionedRegion pr = (PartitionedRegion) getCache().getRegion(rName);
final RegionAdvisor advisor = pr.getRegionAdvisor();
pr.put("oh1", new byte[838860]);
pr.put("oh3", new byte[157287]);
WaitCriterion wc = new WaitCriterion() {
public String description() {
return "verify critical state";
}
public boolean done() {
for (final ProxyBucketRegion bucket : advisor.getProxyBucketArray()) {
if (bucket.isBucketSick()) {
return true;
}
}
return false;
}
};
Wait.waitForCriterion(wc, 30 * 1000, 10, true);
// reload with same key again and again
final Integer k = new Integer(2);
final Integer expectedInvocations3 = new Integer(expectedInvocations.getAndIncrement());
// load
assertEquals(k.toString(), pr.get(k, expectedInvocations3));
assertFalse(pr.containsKey(k));
Integer expectedInvocations4 = new Integer(expectedInvocations.getAndIncrement());
// load
assertEquals(k.toString(), pr.get(k, expectedInvocations4));
assertFalse(pr.containsKey(k));
Integer expectedInvocations5 = new Integer(expectedInvocations.get());
// load
assertEquals(k.toString(), pr.get(k, expectedInvocations5));
assertFalse(pr.containsKey(k));
return expectedInvocations5;
}
});
expectedInvocations.set(ex.intValue());
ex = (Integer) accessor.invoke(new SerializableCallable("During critical state on datastore, assert accesor load behavior") {
public Object call() throws Exception {
// reload with same key again and again
final Integer k = new Integer(2);
Integer expectedInvocations6 = new Integer(expectedInvocations.incrementAndGet());
Region<Integer, String> r = getCache().getRegion(rName);
// load
assertEquals(k.toString(), r.get(k, expectedInvocations6));
assertFalse(r.containsKey(k));
Integer expectedInvocations7 = new Integer(expectedInvocations.incrementAndGet());
// load
assertEquals(k.toString(), r.get(k, expectedInvocations7));
assertFalse(r.containsKey(k));
return expectedInvocations7;
}
});
expectedInvocations.set(ex.intValue());
ex = (Integer) ds1.invoke(new SerializableCallable("Set safe state on datastore, assert local load behavior") {
public Object call() throws Exception {
final PartitionedRegion r = (PartitionedRegion) getCache().getRegion(rName);
r.destroy("oh3");
WaitCriterion wc = new WaitCriterion() {
public String description() {
return "verify critical state";
}
public boolean done() {
return !r.memoryThresholdReached.get();
}
};
Wait.waitForCriterion(wc, 30 * 1000, 10, true);
// same key as previously used, this time is should stick
Integer k = new Integer(3);
Integer expectedInvocations8 = new Integer(expectedInvocations.incrementAndGet());
// last load for 3
assertEquals(k.toString(), r.get(k, expectedInvocations8));
assertTrue(r.containsKey(k));
return expectedInvocations8;
}
});
expectedInvocations.set(ex.intValue());
accessor.invoke(new SerializableCallable("Data store in safe state, assert load behavior, accessor sets critical state, assert load behavior") {
public Object call() throws Exception {
final OffHeapMemoryMonitor ohmm = ((InternalResourceManager) getCache().getResourceManager()).getOffHeapMonitor();
assertFalse(ohmm.getState().isCritical());
Integer k = new Integer(4);
Integer expectedInvocations9 = new Integer(expectedInvocations.incrementAndGet());
final PartitionedRegion r = (PartitionedRegion) getCache().getRegion(rName);
// load for 4
assertEquals(k.toString(), r.get(k, expectedInvocations9));
assertTrue(r.containsKey(k));
// no load
assertEquals(k.toString(), r.get(k, expectedInvocations9));
// Go critical in accessor
r.put("oh3", new byte[157287]);
WaitCriterion wc = new WaitCriterion() {
public String description() {
return "verify critical state";
}
public boolean done() {
return r.memoryThresholdReached.get();
}
};
k = new Integer(5);
Integer expectedInvocations10 = new Integer(expectedInvocations.incrementAndGet());
// load for key 5
assertEquals(k.toString(), r.get(k, expectedInvocations10));
assertTrue(r.containsKey(k));
// no load
assertEquals(k.toString(), r.get(k, expectedInvocations10));
// Clean up critical state
r.destroy("oh3");
wc = new WaitCriterion() {
public String description() {
return "verify critical state";
}
public boolean done() {
return !ohmm.getState().isCritical();
}
};
return expectedInvocations10;
}
});
accessor.invoke(removeExpectedException);
ds1.invoke(removeExpectedException);
}
Aggregations