use of org.apache.geode.internal.cache.BucketRegionQueue in project geode by apache.
the class ParallelGatewaySenderQueueJUnitTest method whenGatewayEventUnableToResolveFromOffHeapTheStatForNotQueuedConflatedShouldBeIncremented.
@Test
public void whenGatewayEventUnableToResolveFromOffHeapTheStatForNotQueuedConflatedShouldBeIncremented() throws Exception {
GatewaySenderStats stats = mockGatewaySenderStats();
GatewaySenderEventImpl event = mock(GatewaySenderEventImpl.class);
when(event.makeHeapCopyIfOffHeap()).thenReturn(null);
GatewaySenderEventImpl eventResolvesFromOffHeap = mock(GatewaySenderEventImpl.class);
when(eventResolvesFromOffHeap.makeHeapCopyIfOffHeap()).thenReturn(eventResolvesFromOffHeap);
Queue backingList = new LinkedList();
backingList.add(event);
backingList.add(eventResolvesFromOffHeap);
BucketRegionQueue bucketRegionQueue = mockBucketRegionQueue(backingList);
TestableParallelGatewaySenderQueue queue = new TestableParallelGatewaySenderQueue(sender, Collections.emptySet(), 0, 1, metaRegionFactory);
queue.setMockedAbstractBucketRegionQueue(bucketRegionQueue);
List peeked = queue.peek(1, 1000);
assertEquals(1, peeked.size());
verify(stats, times(1)).incEventsNotQueuedConflated();
}
use of org.apache.geode.internal.cache.BucketRegionQueue in project geode by apache.
the class ParallelGatewaySenderQueueJUnitTest method whenEventReleaseFromOffHeapFailsExceptionShouldNotBeThrownToAckReaderThread.
@Test
public void whenEventReleaseFromOffHeapFailsExceptionShouldNotBeThrownToAckReaderThread() throws Exception {
GatewaySenderEventImpl event = mock(GatewaySenderEventImpl.class);
when(event.makeHeapCopyIfOffHeap()).thenReturn(event);
Mockito.doThrow(new IllegalStateException()).when(event).release();
Queue backingList = new LinkedList();
backingList.add(event);
BucketRegionQueue bucketRegionQueue = mockBucketRegionQueue(backingList);
TestableParallelGatewaySenderQueue queue = new TestableParallelGatewaySenderQueue(sender, Collections.emptySet(), 0, 1, metaRegionFactory);
queue.setMockedAbstractBucketRegionQueue(bucketRegionQueue);
List peeked = queue.peek(1, 1000);
assertEquals(1, peeked.size());
queue.remove();
}
use of org.apache.geode.internal.cache.BucketRegionQueue in project geode by apache.
the class ParallelGatewaySenderQueueJUnitTest method whenNullPeekedEventFromBucketRegionQueueTheStatForNotQueuedConflatedShouldBeIncremented.
@Test
public void whenNullPeekedEventFromBucketRegionQueueTheStatForNotQueuedConflatedShouldBeIncremented() throws Exception {
GatewaySenderStats stats = mockGatewaySenderStats();
GatewaySenderEventImpl eventResolvesFromOffHeap = mock(GatewaySenderEventImpl.class);
when(eventResolvesFromOffHeap.makeHeapCopyIfOffHeap()).thenReturn(eventResolvesFromOffHeap);
Queue backingList = new LinkedList();
backingList.add(null);
backingList.add(eventResolvesFromOffHeap);
BucketRegionQueue bucketRegionQueue = mockBucketRegionQueue(backingList);
TestableParallelGatewaySenderQueue queue = new TestableParallelGatewaySenderQueue(sender, Collections.emptySet(), 0, 1, metaRegionFactory);
queue.setMockedAbstractBucketRegionQueue(bucketRegionQueue);
List peeked = queue.peek(1, 1000);
assertEquals(1, peeked.size());
verify(stats, times(1)).incEventsNotQueuedConflated();
}
use of org.apache.geode.internal.cache.BucketRegionQueue in project geode by apache.
the class ParallelGatewaySenderQueueJUnitTest method mockBucketRegionQueue.
private BucketRegionQueue mockBucketRegionQueue(final Queue backingList) {
PartitionedRegion mockBucketRegion = mockPR("bucketRegion");
// These next mocked return calls are for when peek is called. It ends up checking these on the
// mocked pr region
when(mockBucketRegion.getLocalMaxMemory()).thenReturn(100);
when(mockBucketRegion.size()).thenReturn(backingList.size());
BucketRegionQueue bucketRegionQueue = mock(BucketRegionQueue.class);
when(bucketRegionQueue.getPartitionedRegion()).thenReturn(mockBucketRegion);
when(bucketRegionQueue.peek()).thenAnswer((Answer) invocation -> backingList.poll());
return bucketRegionQueue;
}
use of org.apache.geode.internal.cache.BucketRegionQueue 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);
}
Aggregations