use of org.apache.geode.CancelCriterion in project geode by apache.
the class ConnectionJUnitTest method testSuspicionRaised.
/**
* Test whether suspicion is raised about a member that closes its shared/unordered TCPConduit
* connection
*/
@Test
public void testSuspicionRaised() throws Exception {
// this test has to create a lot of mocks because Connection
// uses a lot of objects
// mock the socket
ConnectionTable table = mock(ConnectionTable.class);
DM distMgr = mock(DM.class);
MembershipManager membership = mock(MembershipManager.class);
TCPConduit conduit = mock(TCPConduit.class);
// mock the connection table and conduit
when(table.getConduit()).thenReturn(conduit);
CancelCriterion stopper = mock(CancelCriterion.class);
when(stopper.cancelInProgress()).thenReturn(null);
when(conduit.getCancelCriterion()).thenReturn(stopper);
when(conduit.getSocketId()).thenReturn(new InetSocketAddress(SocketCreator.getLocalHost(), 10337));
// NIO can't be mocked because SocketChannel has a final method that
// is used by Connection - configureBlocking
when(conduit.useNIO()).thenReturn(false);
// mock the distribution manager and membership manager
when(distMgr.getMembershipManager()).thenReturn(membership);
when(conduit.getDM()).thenReturn(distMgr);
when(table.getDM()).thenReturn(distMgr);
SocketCloser closer = mock(SocketCloser.class);
when(table.getSocketCloser()).thenReturn(closer);
InputStream instream = mock(InputStream.class);
when(instream.read()).thenReturn(-1);
Socket socket = mock(Socket.class);
when(socket.getInputStream()).thenReturn(instream);
Connection conn = new Connection(table, socket);
conn.setSharedUnorderedForTest();
conn.run();
verify(membership).suspectMember(any(InternalDistributedMember.class), any(String.class));
}
use of org.apache.geode.CancelCriterion in project geode by apache.
the class EventTrackerTest method setUp.
@Before
public void setUp() {
lr = mock(LocalRegion.class);
ra = mock(RegionAttributes.class);
when(lr.createStopper()).thenCallRealMethod();
CancelCriterion stopper = lr.createStopper();
when(lr.getStopper()).thenReturn(stopper);
memberId = mock(ClientProxyMembershipID.class);
when(lr.getAttributes()).thenReturn(ra);
when(ra.getDataPolicy()).thenReturn(mock(DataPolicy.class));
when(lr.getConcurrencyChecksEnabled()).thenReturn(true);
member = mock(DistributedMember.class);
}
use of org.apache.geode.CancelCriterion in project geode by apache.
the class ParallelQueueRemovalMessageJUnitTest method createGatewaySender.
private void createGatewaySender() {
// Mock gateway sender
this.sender = mock(AbstractGatewaySender.class);
when(this.queueRegion.getParallelGatewaySender()).thenReturn(this.sender);
when(this.sender.getQueues()).thenReturn(null);
when(this.sender.getDispatcherThreads()).thenReturn(1);
when(this.sender.getCache()).thenReturn(this.cache);
CancelCriterion cancelCriterion = mock(CancelCriterion.class);
when(sender.getCancelCriterion()).thenReturn(cancelCriterion);
}
use of org.apache.geode.CancelCriterion in project geode by apache.
the class Fakes method cache.
/**
* A fake cache, which contains a fake distributed system, distribution manager, etc.
*/
public static GemFireCacheImpl cache() {
GemFireCacheImpl cache = mock(GemFireCacheImpl.class);
InternalDistributedSystem system = mock(InternalDistributedSystem.class);
DistributionConfig config = mock(DistributionConfig.class);
DistributionManager distributionManager = mock(DistributionManager.class);
CancelCriterion systemCancelCriterion = mock(CancelCriterion.class);
DSClock clock = mock(DSClock.class);
LogWriter logger = mock(LogWriter.class);
Statistics stats = mock(Statistics.class);
InternalDistributedMember member;
member = new InternalDistributedMember("localhost", 5555);
when(config.getCacheXmlFile()).thenReturn(new File(""));
when(config.getDeployWorkingDir()).thenReturn(new File("."));
when(cache.getDistributedSystem()).thenReturn(system);
when(cache.getInternalDistributedSystem()).thenReturn(system);
when(cache.getSystem()).thenReturn(system);
when(cache.getMyId()).thenReturn(member);
when(cache.getDistributionManager()).thenReturn(distributionManager);
when(cache.getCancelCriterion()).thenReturn(systemCancelCriterion);
when(cache.getCachePerfStats()).thenReturn(mock(CachePerfStats.class));
when(system.getDistributedMember()).thenReturn(member);
when(system.getConfig()).thenReturn(config);
when(system.getDistributionManager()).thenReturn(distributionManager);
when(system.getCancelCriterion()).thenReturn(systemCancelCriterion);
when(system.getClock()).thenReturn(clock);
when(system.getLogWriter()).thenReturn(logger);
when(system.createAtomicStatistics(any(), any(), anyLong())).thenReturn(stats);
when(system.createAtomicStatistics(any(), any())).thenReturn(stats);
when(distributionManager.getId()).thenReturn(member);
when(distributionManager.getDistributionManagerId()).thenReturn(member);
when(distributionManager.getConfig()).thenReturn(config);
when(distributionManager.getSystem()).thenReturn(system);
when(distributionManager.getCancelCriterion()).thenReturn(systemCancelCriterion);
return cache;
}
use of org.apache.geode.CancelCriterion in project geode by apache.
the class LuceneQueryFunctionJUnitTest method whenServiceReturnsNullIndexButHasDefinedLuceneIndexDuringQueryExecutionShouldBlockUntilAvailable.
@Test
public void whenServiceReturnsNullIndexButHasDefinedLuceneIndexDuringQueryExecutionShouldBlockUntilAvailable() throws Exception {
LuceneServiceImpl mockServiceImpl = mock(LuceneServiceImpl.class);
when(mockCache.getService(any())).thenReturn(mockServiceImpl);
when(mockServiceImpl.getIndex(eq("indexName"), eq(regionPath))).thenAnswer(new Answer() {
private boolean calledFirstTime = false;
@Override
public Object answer(final InvocationOnMock invocation) throws Throwable {
if (calledFirstTime == false) {
calledFirstTime = true;
return null;
} else {
return mockIndex;
}
}
});
when(mockServiceImpl.getDefinedIndex(eq("indexName"), eq(regionPath))).thenAnswer(new Answer() {
private int count = 10;
@Override
public Object answer(final InvocationOnMock invocation) throws Throwable {
if (count-- > 0) {
return mock(LuceneIndexCreationProfile.class);
}
return null;
}
});
when(mockContext.getDataSet()).thenReturn(mockRegion);
when(mockContext.getArguments()).thenReturn(searchArgs);
when(mockContext.<TopEntriesCollector>getResultSender()).thenReturn(mockResultSender);
CancelCriterion mockCancelCriterion = mock(CancelCriterion.class);
when(mockCache.getCancelCriterion()).thenReturn(mockCancelCriterion);
when(mockCancelCriterion.isCancelInProgress()).thenReturn(false);
LuceneQueryFunction function = new LuceneQueryFunction();
function.execute(mockContext);
}
Aggregations