@Override public AsyncEventQueue getAsyncEventQueue(String id) { for (AsyncEventQueue asyncEventQueue : this.asyncEventQueues) { if (asyncEventQueue.getId().equals(id)) { return asyncEventQueue; } } return null; }
@Override public AsyncEventQueue getAsyncEventQueue(String id) { for (AsyncEventQueue asyncEventQueue : this.allAsyncEventQueues) { if (asyncEventQueue.getId().equals(id)) { return asyncEventQueue; } } return null; }
public static AsyncEventListener getAsyncEventListener(String asyncEventQueueId) { AsyncEventListener theListener = null; Set<AsyncEventQueue> asyncEventQueues = cache.getAsyncEventQueues(); for (AsyncEventQueue asyncQueue : asyncEventQueues) { if (asyncEventQueueId.equals(asyncQueue.getId())) { return asyncQueue.getAsyncEventListener(); } } return null; }
public static void pauseAsyncEventQueue(String asyncChannelId) { AsyncEventQueue theChannel = null; Set<AsyncEventQueue> asyncEventChannels = cache.getAsyncEventQueues(); for (AsyncEventQueue asyncChannel : asyncEventChannels) { if (asyncChannelId.equals(asyncChannel.getId())) { theChannel = asyncChannel; } } ((AsyncEventQueueImpl) theChannel).getSender().pause(); }
public static void resumeAsyncEventQueue(String asyncQueueId) { AsyncEventQueue theQueue = null; Set<AsyncEventQueue> asyncEventChannels = cache.getAsyncEventQueues(); for (AsyncEventQueue asyncChannel : asyncEventChannels) { if (asyncQueueId.equals(asyncChannel.getId())) { theQueue = asyncChannel; } } ((AsyncEventQueueImpl) theQueue).getSender().resume(); }
public static int getAsyncEventQueueSize(String asyncEventQueueId) { AsyncEventQueue theQueue = null; Set<AsyncEventQueue> asyncEventQueues = cache.getAsyncEventQueues(); for (AsyncEventQueue asyncQueue : asyncEventQueues) { if (asyncEventQueueId.equals(asyncQueue.getId())) { theQueue = asyncQueue; } } assertNotNull(theQueue); return theQueue.size(); }
public static void checkAsyncEventQueueConflatedStats(String asyncEventQueueId, final int eventsConflated) { Set<AsyncEventQueue> queues = cache.getAsyncEventQueues(); AsyncEventQueue queue = null; for (AsyncEventQueue q : queues) { if (q.getId().equals(asyncEventQueueId)) { queue = q; break; } } final AsyncEventQueueStats statistics = ((AsyncEventQueueImpl) queue).getStatistics(); assertEquals(eventsConflated, statistics.getEventsNotQueuedConflated()); }
public static void checkAsyncEventQueueBatchStats(String asyncQueueId, final int batches) { Set<AsyncEventQueue> queues = cache.getAsyncEventQueues(); AsyncEventQueue queue = null; for (AsyncEventQueue q : queues) { if (q.getId().equals(asyncQueueId)) { queue = q; break; } } final AsyncEventQueueStats statistics = ((AsyncEventQueueImpl) queue).getStatistics(); assert (statistics.getBatchesDistributed() >= batches); assertEquals(0, statistics.getBatchesRedistributed()); }
protected void setAsyncEventQueueDetails(final InternalCache cache, final DiskStore diskStore, final DiskStoreDetails diskStoreDetails) { for (AsyncEventQueue queue : cache.getAsyncEventQueues()) { if (isUsingDiskStore(queue, diskStore)) { diskStoreDetails.add(new DiskStoreDetails.AsyncEventQueueDetails(queue.getId())); } } }
public static void pauseAsyncEventQueueAndWaitForDispatcherToPause(String asyncChannelId) { AsyncEventQueue theChannel = null; Set<AsyncEventQueue> asyncEventChannels = cache.getAsyncEventQueues(); for (AsyncEventQueue asyncChannel : asyncEventChannels) { if (asyncChannelId.equals(asyncChannel.getId())) { theChannel = asyncChannel; break; } } ((AsyncEventQueueImpl) theChannel).getSender().pause(); ((AbstractGatewaySender) ((AsyncEventQueueImpl) theChannel).getSender()).getEventProcessor() .waitForDispatcherToPause(); }
@Before public void setUp() throws Exception { mockAEQ = mock(AsyncEventQueueImpl.class); mockContext = mock(FunctionContext.class); mockArgs = mock(DestroyAsyncEventQueueFunctionArgs.class); cache = Fakes.cache(); function = spy(DestroyAsyncEventQueueFunction.class); resultSender = mock(ResultSender.class); when(mockContext.getCache()).thenReturn(cache); when(mockContext.getArguments()).thenReturn(mockArgs); when(mockArgs.getId()).thenReturn(TEST_AEQ_ID); when(mockAEQ.getId()).thenReturn(TEST_AEQ_ID); when(mockContext.getResultSender()).thenReturn(resultSender); resultCaptor = ArgumentCaptor.forClass(CliFunctionResult.class); }
@Override public CliFunctionResult executeFunction(final FunctionContext context) { Cache cache = context.getCache(); DistributedMember member = cache.getDistributedSystem().getDistributedMember(); // Identify by name if the name is non-trivial. Otherwise, use the ID String memberId = !member.getName().equals("") ? member.getName() : member.getId(); Set<AsyncEventQueue> asyncEventQueues = cache.getAsyncEventQueues(); List<AsyncEventQueueDetails> details = asyncEventQueues.stream().map(queue -> { AsyncEventListener listener = queue.getAsyncEventListener(); Properties listenerProperties = new Properties(); if (listener instanceof Declarable2) { listenerProperties = ((Declarable2) listener).getConfig(); } return new AsyncEventQueueDetails(queue.getId(), queue.getBatchSize(), queue.isPersistent(), queue.getDiskStoreName(), queue.getMaximumQueueMemory(), listener.getClass().getName(), listenerProperties); }).collect(Collectors.toList()); return new CliFunctionResult(memberId, details); } }
public static Boolean killAsyncEventQueue(String asyncQueueId) { Set<AsyncEventQueue> queues = cache.getAsyncEventQueues(); AsyncEventQueueImpl queue = null; for (AsyncEventQueue q : queues) { if (q.getId().equals(asyncQueueId)) { queue = (AsyncEventQueueImpl) q; break; } } if (queue.isPrimary()) { LogWriterUtils.getLogWriter().info("AsyncEventQueue is killed by a test"); cache.getDistributedSystem().disconnect(); return Boolean.TRUE; } return Boolean.FALSE; }
private Set<DiskStoreDetails.AsyncEventQueueDetails> setupAsyncEventQueuesForTestExecute( final InternalCache mockCache, final String diskStoreName) { final AsyncEventQueue mockAsyncEventQueue1 = mock(AsyncEventQueue.class, "AsyncEventQueue1"); final AsyncEventQueue mockAsyncEventQueue2 = mock(AsyncEventQueue.class, "AsyncEventQueue2"); final AsyncEventQueue mockAsyncEventQueue3 = mock(AsyncEventQueue.class, "AsyncEventQueue3"); when(mockCache.getAsyncEventQueues()).thenReturn( CollectionUtils.asSet(mockAsyncEventQueue1, mockAsyncEventQueue2, mockAsyncEventQueue3)); when(mockAsyncEventQueue1.isPersistent()).thenReturn(true); when(mockAsyncEventQueue1.getDiskStoreName()).thenReturn(diskStoreName); when(mockAsyncEventQueue1.getId()).thenReturn("9876543210"); when(mockAsyncEventQueue2.isPersistent()).thenReturn(false); when(mockAsyncEventQueue3.isPersistent()).thenReturn(true); when(mockAsyncEventQueue3.getDiskStoreName()).thenReturn("memSto"); return CollectionUtils.asSet(createAsyncEventQueueDetails("9876543210")); }
public static void checkAsyncEventQueueUnprocessedStats(String asyncQueueId, int events) { Set<AsyncEventQueue> asyncQueues = cache.getAsyncEventQueues(); AsyncEventQueue queue = null; for (AsyncEventQueue q : asyncQueues) { if (q.getId().equals(asyncQueueId)) { queue = q; break; } } final AsyncEventQueueStats statistics = ((AsyncEventQueueImpl) queue).getStatistics(); assertEquals(events, (statistics.getUnprocessedEventsAddedBySecondary() + statistics.getUnprocessedTokensRemovedBySecondary())); assertEquals(events, (statistics.getUnprocessedEventsRemovedByPrimary() + statistics.getUnprocessedTokensAddedByPrimary())); }
public static void checkAsyncEventQueueStats_Failover(String asyncEventQueueId, final int eventsReceived) { Set<AsyncEventQueue> asyncEventQueues = cache.getAsyncEventQueues(); AsyncEventQueue queue = null; for (AsyncEventQueue q : asyncEventQueues) { if (q.getId().equals(asyncEventQueueId)) { queue = q; break; } } final AsyncEventQueueStats statistics = ((AsyncEventQueueImpl) queue).getStatistics(); assertEquals(eventsReceived, statistics.getEventsReceived()); assertEquals(eventsReceived, (statistics.getEventsQueued() + statistics.getUnprocessedTokensAddedByPrimary() + statistics.getUnprocessedEventsRemovedByPrimary())); }
@Test public void testSetAsyncEventQueueDetails() { final String diskStoreName = "testDiskStore"; final DiskStore mockDiskStore = mock(DiskStore.class, "DiskStore"); final AsyncEventQueue mockQueue1 = mock(AsyncEventQueue.class, "AsyncEvenQueue1"); final AsyncEventQueue mockQueue2 = mock(AsyncEventQueue.class, "AsyncEvenQueue2"); final AsyncEventQueue mockQueue3 = mock(AsyncEventQueue.class, "AsyncEvenQueue3"); when(mockCache.getAsyncEventQueues()) .thenReturn(CollectionUtils.asSet(mockQueue1, mockQueue2, mockQueue3)); when(mockQueue1.isPersistent()).thenReturn(true); when(mockQueue1.getDiskStoreName()).thenReturn(diskStoreName); when(mockQueue1.getId()).thenReturn("q1"); when(mockQueue2.isPersistent()).thenReturn(true); when(mockQueue2.getDiskStoreName()).thenReturn(null); when(mockQueue3.isPersistent()).thenReturn(false); when(mockDiskStore.getName()).thenReturn(diskStoreName); final Set<DiskStoreDetails.AsyncEventQueueDetails> expectedAsyncEventQueueDetails = CollectionUtils.asSet(createAsyncEventQueueDetails("q1")); final DiskStoreDetails diskStoreDetails = new DiskStoreDetails(diskStoreName, "memberOne"); final DescribeDiskStoreFunction function = new DescribeDiskStoreFunction(); function.setAsyncEventQueueDetails(mockCache, mockDiskStore, diskStoreDetails); assertAsyncEventQueueDetails(expectedAsyncEventQueueDetails, diskStoreDetails); verify(mockDiskStore, atLeastOnce()).getName(); }
protected void handleAsyncEventQueueCreation(AsyncEventQueue queue) throws ManagementException { if (!isServiceInitialised("handleAsyncEventQueueCreation")) { return; } AsyncEventQueueMBeanBridge bridge = new AsyncEventQueueMBeanBridge(queue); AsyncEventQueueMXBean queueMBean = new AsyncEventQueueMBean(bridge); ObjectName senderObjectName = MBeanJMXAdapter.getAsyncEventQueueMBeanName( internalCache.getDistributedSystem().getDistributedMember(), queue.getId()); ObjectName changedMBeanName = service.registerInternalMBean(queueMBean, senderObjectName); service.federate(changedMBeanName, AsyncEventQueueMXBean.class, true); Notification notification = new Notification(JMXNotificationType.ASYNC_EVENT_QUEUE_CREATED, memberSource, SequenceNumber.next(), System.currentTimeMillis(), ManagementConstants.ASYNC_EVENT_QUEUE_CREATED_PREFIX); memberLevelNotifEmitter.sendNotification(notification); }
/** * Validate whether all the attributes set on AsyncEventQueueFactory are set on the sender * underneath the AsyncEventQueue. */ public static void validateAsyncEventQueueAttributes(String asyncChannelId, int maxQueueMemory, int batchSize, int batchTimeInterval, boolean isPersistent, String diskStoreName, boolean isDiskSynchronous, boolean batchConflationEnabled) { AsyncEventQueue theChannel = null; Set<AsyncEventQueue> asyncEventChannels = cache.getAsyncEventQueues(); for (AsyncEventQueue asyncChannel : asyncEventChannels) { if (asyncChannelId.equals(asyncChannel.getId())) { theChannel = asyncChannel; } } GatewaySender theSender = ((AsyncEventQueueImpl) theChannel).getSender(); assertEquals("maxQueueMemory", maxQueueMemory, theSender.getMaximumQueueMemory()); assertEquals("batchSize", batchSize, theSender.getBatchSize()); assertEquals("batchTimeInterval", batchTimeInterval, theSender.getBatchTimeInterval()); assertEquals("isPersistent", isPersistent, theSender.isPersistenceEnabled()); assertEquals("diskStoreName", diskStoreName, theSender.getDiskStoreName()); assertEquals("isDiskSynchronous", isDiskSynchronous, theSender.isDiskSynchronous()); assertEquals("batchConflation", batchConflationEnabled, theSender.isBatchConflationEnabled()); }
/** * Validate whether all the attributes set on AsyncEventQueueFactory are set on the sender * underneath the AsyncEventQueue. */ public static void validateConcurrentAsyncEventQueueAttributes(String asyncChannelId, int maxQueueMemory, int batchSize, int batchTimeInterval, boolean isPersistent, String diskStoreName, boolean isDiskSynchronous, boolean batchConflationEnabled, int dispatcherThreads, OrderPolicy policy) { AsyncEventQueue theChannel = null; Set<AsyncEventQueue> asyncEventChannels = cache.getAsyncEventQueues(); for (AsyncEventQueue asyncChannel : asyncEventChannels) { if (asyncChannelId.equals(asyncChannel.getId())) { theChannel = asyncChannel; } } GatewaySender theSender = ((AsyncEventQueueImpl) theChannel).getSender(); assertEquals("maxQueueMemory", maxQueueMemory, theSender.getMaximumQueueMemory()); assertEquals("batchSize", batchSize, theSender.getBatchSize()); assertEquals("batchTimeInterval", batchTimeInterval, theSender.getBatchTimeInterval()); assertEquals("isPersistent", isPersistent, theSender.isPersistenceEnabled()); assertEquals("diskStoreName", diskStoreName, theSender.getDiskStoreName()); assertEquals("isDiskSynchronous", isDiskSynchronous, theSender.isDiskSynchronous()); assertEquals("batchConflation", batchConflationEnabled, theSender.isBatchConflationEnabled()); assertEquals("dispatcherThreads", dispatcherThreads, theSender.getDispatcherThreads()); assertEquals("orderPolicy", policy, theSender.getOrderPolicy()); }