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);
}
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();
}
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();
}
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();
}
}
}
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);
}
}
Aggregations