Search in sources :

Example 1 with BucketRegionQueue

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();
}
Also used : GatewaySenderStats(org.apache.geode.internal.cache.wan.GatewaySenderStats) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) GatewaySenderEventImpl(org.apache.geode.internal.cache.wan.GatewaySenderEventImpl) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) Queue(java.util.Queue) LinkedList(java.util.LinkedList) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 2 with BucketRegionQueue

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();
}
Also used : BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) GatewaySenderEventImpl(org.apache.geode.internal.cache.wan.GatewaySenderEventImpl) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) Queue(java.util.Queue) LinkedList(java.util.LinkedList) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 3 with BucketRegionQueue

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();
}
Also used : GatewaySenderStats(org.apache.geode.internal.cache.wan.GatewaySenderStats) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) GatewaySenderEventImpl(org.apache.geode.internal.cache.wan.GatewaySenderEventImpl) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) Queue(java.util.Queue) LinkedList(java.util.LinkedList) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 4 with BucketRegionQueue

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;
}
Also used : ParallelGatewaySenderQueueMetaRegion(org.apache.geode.internal.cache.wan.parallel.ParallelGatewaySenderQueue.ParallelGatewaySenderQueueMetaRegion) HashMap(java.util.HashMap) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Region(org.apache.geode.cache.Region) LinkedList(java.util.LinkedList) Before(org.junit.Before) GatewaySenderStats(org.apache.geode.internal.cache.wan.GatewaySenderStats) Iterator(java.util.Iterator) CancelCriterion(org.apache.geode.CancelCriterion) AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) MetaRegionFactory(org.apache.geode.internal.cache.wan.parallel.ParallelGatewaySenderQueue.MetaRegionFactory) Set(java.util.Set) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Mockito(org.mockito.Mockito) List(java.util.List) DataPolicy(org.apache.geode.cache.DataPolicy) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Queue(java.util.Queue) Assert(org.junit.Assert) GatewaySenderEventImpl(org.apache.geode.internal.cache.wan.GatewaySenderEventImpl) Collections(java.util.Collections) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) AbstractBucketRegionQueue(org.apache.geode.internal.cache.AbstractBucketRegionQueue) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Example 5 with 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);
}
Also used : RegionAdvisor(org.apache.geode.internal.cache.partitioned.RegionAdvisor) RegionAttributes(org.apache.geode.cache.RegionAttributes) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) BucketRegionQueueHelper(org.apache.geode.internal.cache.BucketRegionQueueHelper) AttributesFactory(org.apache.geode.cache.AttributesFactory) BucketRegionQueue(org.apache.geode.internal.cache.BucketRegionQueue) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ProxyBucketRegion(org.apache.geode.internal.cache.ProxyBucketRegion) DistributedMember(org.apache.geode.distributed.DistributedMember) EventID(org.apache.geode.internal.cache.EventID) BucketAdvisor(org.apache.geode.internal.cache.BucketAdvisor)

Aggregations

BucketRegionQueue (org.apache.geode.internal.cache.BucketRegionQueue)10 AbstractBucketRegionQueue (org.apache.geode.internal.cache.AbstractBucketRegionQueue)9 ArrayList (java.util.ArrayList)5 GatewaySenderEventImpl (org.apache.geode.internal.cache.wan.GatewaySenderEventImpl)5 LinkedList (java.util.LinkedList)4 List (java.util.List)4 Queue (java.util.Queue)4 UnitTest (org.apache.geode.test.junit.categories.UnitTest)4 Test (org.junit.Test)4 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 GatewaySenderStats (org.apache.geode.internal.cache.wan.GatewaySenderStats)3 HashMap (java.util.HashMap)2 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1