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);
}
use of org.apache.geode.CancelCriterion in project geode by apache.
the class StatSamplerIntegrationTest method testStatSampler.
@Test
public void testStatSampler() throws Exception {
StatArchiveWriter.setTraceFilter("st1_1", "ST1");
File folder = temporaryFolder.newFolder();
String archiveFileName = folder.getAbsolutePath() + File.separator + getName() + ".gfs";
System.setProperty("stats.log-level", "config");
System.setProperty("stats.disable", "false");
System.setProperty("stats.name", getName());
System.setProperty("stats.archive-file", archiveFileName);
System.setProperty("stats.file-size-limit", "0");
System.setProperty("stats.disk-space-limit", "0");
System.setProperty("stats.sample-rate", "100");
final CancelCriterion stopper = new CancelCriterion() {
public String cancelInProgress() {
return null;
}
public RuntimeException generateCancelledException(Throwable e) {
return null;
}
};
final LocalStatisticsFactory factory = new LocalStatisticsFactory(stopper);
final StatisticDescriptor[] statsST1 = new StatisticDescriptor[] { factory.createDoubleCounter("double_counter_1", "d1", "u1"), factory.createDoubleCounter("double_counter_2", "d2", "u2", true), factory.createDoubleGauge("double_gauge_3", "d3", "u3"), factory.createDoubleGauge("double_gauge_4", "d4", "u4", false), factory.createIntCounter("int_counter_5", "d5", "u5"), factory.createIntCounter("int_counter_6", "d6", "u6", true), factory.createIntGauge("int_gauge_7", "d7", "u7"), factory.createIntGauge("int_gauge_8", "d8", "u8", false), factory.createLongCounter("long_counter_9", "d9", "u9"), factory.createLongCounter("long_counter_10", "d10", "u10", true), factory.createLongGauge("long_gauge_11", "d11", "u11"), factory.createLongGauge("long_gauge_12", "d12", "u12", false), factory.createLongGauge("sampled_long", "d13", "u13", false), factory.createIntGauge("sampled_int", "d14", "u14", false), factory.createDoubleGauge("sampled_double", "d15", "u15", false) };
final StatisticsType ST1 = factory.createType("ST1", "ST1", statsST1);
final Statistics st1_1 = factory.createAtomicStatistics(ST1, "st1_1", 1);
st1_1.setIntSupplier("sampled_int", () -> 5);
getOrCreateExpectedValueMap(st1_1).put("sampled_int", 5);
st1_1.setLongSupplier("sampled_long", () -> 6);
getOrCreateExpectedValueMap(st1_1).put("sampled_long", 6);
st1_1.setDoubleSupplier("sampled_double", () -> 7.0);
getOrCreateExpectedValueMap(st1_1).put("sampled_double", 7.0);
await("awaiting StatSampler readiness").atMost(30, SECONDS).until(() -> hasSamplerStatsInstances(factory));
Statistics[] samplerStatsInstances = factory.findStatisticsByTextId("statSampler");
assertNotNull(samplerStatsInstances);
assertEquals(1, samplerStatsInstances.length);
final Statistics samplerStats = samplerStatsInstances[0];
incDouble(st1_1, "double_counter_1", 1);
incDouble(st1_1, "double_gauge_3", 3);
incInt(st1_1, "int_counter_5", 5);
incInt(st1_1, "int_gauge_7", 7);
incLong(st1_1, "long_counter_9", 9);
incLong(st1_1, "long_gauge_11", 11);
awaitStatSample(samplerStats);
incDouble(st1_1, "double_counter_1", 1);
incDouble(st1_1, "double_counter_2", 1);
incDouble(st1_1, "double_gauge_3", 1);
incDouble(st1_1, "double_gauge_4", 1);
incInt(st1_1, "int_counter_5", 1);
incInt(st1_1, "int_counter_6", 1);
awaitStatSample(samplerStats);
incDouble(st1_1, "double_counter_1", 1);
incDouble(st1_1, "double_counter_2", 1);
incDouble(st1_1, "double_gauge_3", 1);
incDouble(st1_1, "double_gauge_4", 1);
incInt(st1_1, "int_counter_5", 1);
incInt(st1_1, "int_counter_6", 1);
incInt(st1_1, "int_gauge_7", 1);
incInt(st1_1, "int_gauge_8", 1);
incLong(st1_1, "long_counter_9", 1);
incLong(st1_1, "long_counter_10", 1);
incLong(st1_1, "long_gauge_11", 1);
incLong(st1_1, "long_gauge_12", 1);
awaitStatSample(samplerStats);
incDouble(st1_1, "double_counter_1", 1);
incDouble(st1_1, "double_counter_2", 1);
incDouble(st1_1, "double_gauge_3", -1);
incDouble(st1_1, "double_gauge_4", 1);
incInt(st1_1, "int_counter_5", 1);
incInt(st1_1, "int_counter_6", 1);
incInt(st1_1, "int_gauge_7", -1);
incInt(st1_1, "int_gauge_8", 1);
incLong(st1_1, "long_counter_9", 1);
incLong(st1_1, "long_counter_10", 1);
incLong(st1_1, "long_gauge_11", -1);
incLong(st1_1, "long_gauge_12", 1);
awaitStatSample(samplerStats);
incDouble(st1_1, "double_counter_1", 1);
incDouble(st1_1, "double_counter_2", 1);
incDouble(st1_1, "double_gauge_3", 1);
incDouble(st1_1, "double_gauge_4", 1);
incInt(st1_1, "int_counter_5", 1);
incInt(st1_1, "int_counter_6", 1);
incInt(st1_1, "int_gauge_7", 1);
incInt(st1_1, "int_gauge_8", 1);
incLong(st1_1, "long_counter_9", 1);
incLong(st1_1, "long_counter_10", 1);
incLong(st1_1, "long_gauge_11", 1);
incLong(st1_1, "long_gauge_12", 1);
awaitStatSample(samplerStats);
awaitStatSample(samplerStats);
awaitStatSample(samplerStats);
incDouble(st1_1, "double_counter_1", 1);
incDouble(st1_1, "double_gauge_3", 3);
incInt(st1_1, "int_counter_5", 5);
incInt(st1_1, "int_gauge_7", 7);
incLong(st1_1, "long_counter_9", 9);
incLong(st1_1, "long_gauge_11", 11);
awaitStatSample(samplerStats);
incDouble(st1_1, "double_counter_1", 1);
incDouble(st1_1, "double_counter_2", 1);
incDouble(st1_1, "double_gauge_3", 1);
incDouble(st1_1, "double_gauge_4", 1);
incInt(st1_1, "int_counter_5", 1);
incInt(st1_1, "int_counter_6", 1);
awaitStatSample(samplerStats);
incDouble(st1_1, "double_counter_1", 1);
incDouble(st1_1, "double_counter_2", 1);
incDouble(st1_1, "double_gauge_3", 1);
incDouble(st1_1, "double_gauge_4", 1);
incInt(st1_1, "int_counter_5", 1);
incInt(st1_1, "int_counter_6", 1);
incInt(st1_1, "int_gauge_7", 1);
incInt(st1_1, "int_gauge_8", 1);
incLong(st1_1, "long_counter_9", 1);
incLong(st1_1, "long_counter_10", 1);
incLong(st1_1, "long_gauge_11", 1);
incLong(st1_1, "long_gauge_12", 1);
awaitStatSample(samplerStats);
incDouble(st1_1, "double_counter_1", 1);
incDouble(st1_1, "double_counter_2", 1);
incDouble(st1_1, "double_gauge_3", -1);
incDouble(st1_1, "double_gauge_4", 1);
incInt(st1_1, "int_counter_5", 1);
incInt(st1_1, "int_counter_6", 1);
incInt(st1_1, "int_gauge_7", -1);
incInt(st1_1, "int_gauge_8", 1);
incLong(st1_1, "long_counter_9", 1);
incLong(st1_1, "long_counter_10", 1);
incLong(st1_1, "long_gauge_11", -1);
incLong(st1_1, "long_gauge_12", 1);
awaitStatSample(samplerStats);
incDouble(st1_1, "double_counter_1", 1);
incDouble(st1_1, "double_counter_2", 1);
incDouble(st1_1, "double_gauge_3", 1);
incDouble(st1_1, "double_gauge_4", 1);
incInt(st1_1, "int_counter_5", 1);
incInt(st1_1, "int_counter_6", 1);
incInt(st1_1, "int_gauge_7", 1);
incInt(st1_1, "int_gauge_8", 1);
incLong(st1_1, "long_counter_9", 1);
incLong(st1_1, "long_counter_10", 1);
incLong(st1_1, "long_gauge_11", 1);
incLong(st1_1, "long_gauge_12", 1);
awaitStatSample(samplerStats);
factory.close();
final File archiveFile = new File(System.getProperty("stats.archive-file"));
assertTrue(archiveFile.exists());
final StatArchiveReader reader = new StatArchiveReader(new File[] { archiveFile }, null, false);
List resources = reader.getResourceInstList();
for (Iterator iter = resources.iterator(); iter.hasNext(); ) {
StatArchiveReader.ResourceInst ri = (StatArchiveReader.ResourceInst) iter.next();
String resourceName = ri.getName();
assertNotNull(resourceName);
if (!resourceName.equals("st1_1")) {
logger.info("testStatSampler skipping {}", resourceName);
continue;
}
String expectedStatsType = this.statisticTypes.get(resourceName);
assertNotNull(expectedStatsType);
assertEquals(expectedStatsType, ri.getType().getName());
Map<String, Number> expectedStatValues = this.allStatistics.get(resourceName);
assertNotNull(expectedStatValues);
StatValue[] statValues = ri.getStatValues();
for (int i = 0; i < statValues.length; i++) {
String statName = ri.getType().getStats()[i].getName();
assertNotNull(statName);
assertNotNull(expectedStatValues.get(statName));
assertEquals(statName, statValues[i].getDescriptor().getName());
statValues[i].setFilter(StatValue.FILTER_NONE);
// double[] rawSnapshots = statValues[i].getRawSnapshots();
assertEquals("Value " + i + " for " + statName + " is wrong: " + expectedStatValues, expectedStatValues.get(statName).doubleValue(), statValues[i].getSnapshotsMostRecent(), 0);
}
}
}
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);
}
Aggregations