Search in sources :

Example 6 with CancelCriterion

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));
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InetSocketAddress(java.net.InetSocketAddress) InputStream(java.io.InputStream) CancelCriterion(org.apache.geode.CancelCriterion) DM(org.apache.geode.distributed.internal.DM) MembershipManager(org.apache.geode.distributed.internal.membership.MembershipManager) SocketCloser(org.apache.geode.internal.net.SocketCloser) Socket(java.net.Socket) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Example 7 with CancelCriterion

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);
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) RegionAttributes(org.apache.geode.cache.RegionAttributes) CancelCriterion(org.apache.geode.CancelCriterion) DistributedMember(org.apache.geode.distributed.DistributedMember) DataPolicy(org.apache.geode.cache.DataPolicy) Before(org.junit.Before)

Example 8 with CancelCriterion

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);
}
Also used : CancelCriterion(org.apache.geode.CancelCriterion) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender)

Example 9 with 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;
}
Also used : DistributionConfig(org.apache.geode.distributed.internal.DistributionConfig) DSClock(org.apache.geode.distributed.internal.DSClock) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) LogWriter(org.apache.geode.LogWriter) CancelCriterion(org.apache.geode.CancelCriterion) CachePerfStats(org.apache.geode.internal.cache.CachePerfStats) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Statistics(org.apache.geode.Statistics) File(java.io.File)

Example 10 with CancelCriterion

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);
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CancelCriterion(org.apache.geode.CancelCriterion) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneIndexCreationProfile(org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

CancelCriterion (org.apache.geode.CancelCriterion)16 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)4 Before (org.junit.Before)4 InputStream (java.io.InputStream)3 DistributedMember (org.apache.geode.distributed.DistributedMember)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 Socket (java.net.Socket)2 Iterator (java.util.Iterator)2 SSLSocket (javax.net.ssl.SSLSocket)2 Statistics (org.apache.geode.Statistics)2 RegionAttributes (org.apache.geode.cache.RegionAttributes)2 DM (org.apache.geode.distributed.internal.DM)2 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2