Search in sources :

Example 1 with GatewaySenderStats

use of org.apache.geode.internal.cache.wan.GatewaySenderStats in project geode by apache.

the class GatewayMBeanBridgeJUnitTest method init.

public void init() {
    senderStats = new GatewaySenderStats(system, "test");
    sender = Mockito.mock(AbstractGatewaySender.class);
    Mockito.when(sender.getStatistics()).thenReturn(senderStats);
    bridge = new GatewaySenderMBeanBridge(sender);
    bridge.addGatewaySenderStats(senderStats);
}
Also used : GatewaySenderStats(org.apache.geode.internal.cache.wan.GatewaySenderStats) GatewaySenderMBeanBridge(org.apache.geode.management.internal.beans.GatewaySenderMBeanBridge) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender)

Example 2 with GatewaySenderStats

use of org.apache.geode.internal.cache.wan.GatewaySenderStats 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 3 with GatewaySenderStats

use of org.apache.geode.internal.cache.wan.GatewaySenderStats 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 GatewaySenderStats

use of org.apache.geode.internal.cache.wan.GatewaySenderStats in project geode by apache.

the class SerialGatewaySenderEventProcessor method basicHandleSecondaryEvent.

private void basicHandleSecondaryEvent(final GatewaySenderEventImpl gatewayEvent) {
    boolean freeGatewayEvent = true;
    try {
        GatewaySenderStats statistics = this.sender.getStatistics();
        if (!getSender().getGatewayEventFilters().isEmpty()) {
            try {
                gatewayEvent.initialize();
            } catch (Exception e) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayImpl_EVENT_FAILED_TO_BE_INITIALIZED_0, gatewayEvent), e);
            }
            if (!sender.beforeEnqueue(gatewayEvent)) {
                statistics.incEventsFiltered();
                return;
            }
        }
        Assert.assertHoldsLock(unprocessedEventsLock, true);
        Assert.assertTrue(unprocessedEvents != null);
        // @todo add an assertion that !getPrimary()
        // now we can safely use the unprocessedEvents field
        Long v = this.unprocessedTokens.remove(gatewayEvent.getEventId());
        if (v == null) {
            // first time for the event
            if (logger.isTraceEnabled()) {
                logger.trace("{}: fromSecondary event {}:{}->{} added from unprocessed events map", sender.getId(), gatewayEvent.getEventId(), gatewayEvent.getKey(), gatewayEvent.getValueAsString(true));
            }
            {
                EventWrapper mapValue = new EventWrapper(gatewayEvent);
                EventWrapper oldv = this.unprocessedEvents.put(gatewayEvent.getEventId(), mapValue);
                if (oldv == null) {
                    freeGatewayEvent = false;
                    statistics.incUnprocessedEventsAddedBySecondary();
                } else {
                    // put old one back in
                    this.unprocessedEvents.put(gatewayEvent.getEventId(), oldv);
                    // already added by secondary (i.e. hub)
                    logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayImpl_0_THE_UNPROCESSED_EVENTS_MAP_ALREADY_CONTAINED_AN_EVENT_FROM_THE_HUB_1_SO_IGNORING_NEW_EVENT_2, new Object[] { sender.getId(), v, gatewayEvent }));
                }
            }
        } else {
            // token already added by primary already removed
            if (logger.isTraceEnabled()) {
                logger.trace("{}: Secondary created event {}:{}->{} removed from unprocessed events map", sender.getId(), gatewayEvent.getEventId(), gatewayEvent.getKey(), gatewayEvent.getValueAsString(true));
            }
            statistics.incUnprocessedTokensRemovedBySecondary();
        }
        reapOld(statistics, false);
    } finally {
        if (freeGatewayEvent) {
            gatewayEvent.release();
        }
    }
}
Also used : GatewaySenderStats(org.apache.geode.internal.cache.wan.GatewaySenderStats) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) EventWrapper(org.apache.geode.internal.cache.wan.AbstractGatewaySender.EventWrapper)

Example 5 with GatewaySenderStats

use of org.apache.geode.internal.cache.wan.GatewaySenderStats in project geode by apache.

the class SerialGatewaySenderEventProcessor method basicHandlePrimaryEvent.

protected void basicHandlePrimaryEvent(final GatewaySenderEventImpl gatewayEvent) {
    if (this.sender.isPrimary()) {
        // no need to do anything if we have become the primary
        return;
    }
    GatewaySenderStats statistics = this.sender.getStatistics();
    // Get the event from the map
    synchronized (unprocessedEventsLock) {
        if (this.unprocessedEvents == null)
            return;
        // now we can safely use the unprocessedEvents field
        EventWrapper ew = this.unprocessedEvents.remove(gatewayEvent.getEventId());
        if (ew == null) {
            // first time for the event
            if (logger.isTraceEnabled()) {
                logger.trace("{}: fromPrimary event {} : {}->{} added to unprocessed token map", sender.getId(), gatewayEvent.getEventId(), gatewayEvent.getKey(), gatewayEvent.getValueAsString(true));
            }
            {
                Long mapValue = Long.valueOf(System.currentTimeMillis() + AbstractGatewaySender.TOKEN_TIMEOUT);
                Long oldv = this.unprocessedTokens.put(gatewayEvent.getEventId(), mapValue);
                if (oldv == null) {
                    statistics.incUnprocessedTokensAddedByPrimary();
                } else {
                // its ok for oldv to be non-null
                // this shouldn't happen anymore @todo add an assertion here
                }
            }
        } else {
            // removed (it already was above)
            if (logger.isTraceEnabled()) {
                logger.trace("{}: Primary create/update event {}:{}->{} remove from unprocessed events map", sender.getId(), gatewayEvent.getEventId(), gatewayEvent.getKey(), gatewayEvent.getValueAsString(true));
            }
            ew.event.release();
            statistics.incUnprocessedEventsRemovedByPrimary();
        }
        reapOld(statistics, false);
    }
}
Also used : GatewaySenderStats(org.apache.geode.internal.cache.wan.GatewaySenderStats) EventWrapper(org.apache.geode.internal.cache.wan.AbstractGatewaySender.EventWrapper)

Aggregations

GatewaySenderStats (org.apache.geode.internal.cache.wan.GatewaySenderStats)11 EventWrapper (org.apache.geode.internal.cache.wan.AbstractGatewaySender.EventWrapper)4 GatewaySenderEventImpl (org.apache.geode.internal.cache.wan.GatewaySenderEventImpl)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Queue (java.util.Queue)2 CacheException (org.apache.geode.cache.CacheException)2 AbstractBucketRegionQueue (org.apache.geode.internal.cache.AbstractBucketRegionQueue)2 BucketRegionQueue (org.apache.geode.internal.cache.BucketRegionQueue)2 GatewaySenderEventRemoteDispatcher (org.apache.geode.internal.cache.wan.GatewaySenderEventRemoteDispatcher)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2 Test (org.junit.Test)2 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 CancelException (org.apache.geode.CancelException)1 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1