use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class LuceneSearchIndexFunctionJUnitTest method testExecute.
@Test
@SuppressWarnings("unchecked")
public void testExecute() throws LuceneQueryException {
FunctionContext context = mock(FunctionContext.class);
ResultSender resultSender = mock(ResultSender.class);
GemFireCacheImpl cache = Fakes.cache();
LuceneQueryInfo queryInfo = createMockQueryInfo("index", "region", "field1:region1", "field1", 1);
InternalLuceneService service = getMockLuceneService("A", "Value", "1.2");
Region mockRegion = mock(Region.class);
LuceneSearchIndexFunction function = spy(LuceneSearchIndexFunction.class);
doReturn(queryInfo).when(context).getArguments();
doReturn(resultSender).when(context).getResultSender();
doReturn(cache).when(function).getCache();
when(cache.getService(eq(InternalLuceneService.class))).thenReturn(service);
when(cache.getRegion(queryInfo.getRegionPath())).thenReturn(mockRegion);
function.execute(context);
ArgumentCaptor<Set> resultCaptor = ArgumentCaptor.forClass(Set.class);
verify(resultSender).lastResult(resultCaptor.capture());
Set<LuceneSearchResults> result = resultCaptor.getValue();
assertEquals(1, result.size());
for (LuceneSearchResults searchResult : result) {
assertEquals("A", searchResult.getKey());
assertEquals("Value", searchResult.getValue());
assertEquals(1.2, searchResult.getScore(), .1);
}
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class DescribeDiskStoreFunctionJUnitTest method testExecute.
@Test
public void testExecute() throws Throwable {
final UUID diskStoreId = UUID.randomUUID();
final String diskStoreName = "mockDiskStore";
final String memberId = "mockMemberId";
final String memberName = "mockMemberName";
final InternalCache mockCache = mockContext.mock(InternalCache.class, "Cache");
final InternalDistributedMember mockMember = mockContext.mock(InternalDistributedMember.class, "DistributedMember");
final DiskStore mockDiskStore = createMockDiskStore(diskStoreId, diskStoreName, true, false, 75, 8192l, 500, 120l, 10240, createFileArray("/export/disk/backup", "/export/disk/overflow", "/export/disk/persistence"), createIntArray(10240, 204800, 4096000), 50, 75);
final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "testExecute$FunctionContext");
final TestResultSender testResultSender = new TestResultSender();
mockContext.checking(new Expectations() {
{
oneOf(mockCache).getMyId();
will(returnValue(mockMember));
oneOf(mockCache).findDiskStore(diskStoreName);
will(returnValue(mockDiskStore));
oneOf(mockCache).getPdxPersistent();
will(returnValue(true));
oneOf(mockCache).getPdxDiskStore();
will(returnValue("memoryStore"));
oneOf(mockMember).getId();
will(returnValue(memberId));
oneOf(mockMember).getName();
will(returnValue(memberName));
oneOf(mockFunctionContext).getArguments();
will(returnValue(diskStoreName));
oneOf(mockFunctionContext).getResultSender();
will(returnValue(testResultSender));
}
});
final Set<DiskStoreDetails.RegionDetails> expectedRegionDetails = setupRegionsForTestExecute(mockCache, diskStoreName);
final Set<DiskStoreDetails.GatewayDetails> expectedGatewayDetails = setupGatewaysForTestExecute(mockCache, diskStoreName);
final Set<DiskStoreDetails.CacheServerDetails> expectedCacheServerDetails = setupCacheServersForTestExecute(mockCache, diskStoreName);
final Set<DiskStoreDetails.AsyncEventQueueDetails> expectedAsyncEventQueueDetails = setupAsyncEventQueuesForTestExecute(mockCache, diskStoreName);
final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache);
function.execute(mockFunctionContext);
final List<?> results = testResultSender.getResults();
assertNotNull(results);
assertEquals(1, results.size());
final DiskStoreDetails diskStoreDetails = (DiskStoreDetails) results.get(0);
assertNotNull(diskStoreDetails);
assertEquals(diskStoreId, diskStoreDetails.getId());
assertEquals(diskStoreName, diskStoreDetails.getName());
assertEquals(memberId, diskStoreDetails.getMemberId());
assertEquals(memberName, diskStoreDetails.getMemberName());
assertTrue(diskStoreDetails.getAllowForceCompaction());
assertFalse(diskStoreDetails.getAutoCompact());
assertEquals(75, diskStoreDetails.getCompactionThreshold().intValue());
assertEquals(8192l, diskStoreDetails.getMaxOplogSize().longValue());
assertFalse(diskStoreDetails.isPdxSerializationMetaDataStored());
assertEquals(500, diskStoreDetails.getQueueSize().intValue());
assertEquals(120l, diskStoreDetails.getTimeInterval().longValue());
assertEquals(10240, diskStoreDetails.getWriteBufferSize().intValue());
assertEquals(50.0f, diskStoreDetails.getDiskUsageWarningPercentage().floatValue(), 0.0f);
assertEquals(75.0f, diskStoreDetails.getDiskUsageCriticalPercentage().floatValue(), 0.0f);
final List<String> expectedDiskDirs = Arrays.asList(new File("/export/disk/backup").getAbsolutePath(), new File("/export/disk/overflow").getAbsolutePath(), new File("/export/disk/persistence").getAbsolutePath());
final List<Integer> expectdDiskDirSizes = Arrays.asList(10240, 204800, 4096000);
int count = 0;
for (final DiskStoreDetails.DiskDirDetails diskDirDetails : diskStoreDetails) {
assertTrue(expectedDiskDirs.contains(diskDirDetails.getAbsolutePath()));
assertTrue(expectdDiskDirSizes.contains(diskDirDetails.getSize()));
count++;
}
assertEquals(expectedDiskDirs.size(), count);
assertRegionDetails(expectedRegionDetails, diskStoreDetails);
assertCacheServerDetails(expectedCacheServerDetails, diskStoreDetails);
assertGatewayDetails(expectedGatewayDetails, diskStoreDetails);
assertAsyncEventQueueDetails(expectedAsyncEventQueueDetails, diskStoreDetails);
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class DescribeDiskStoreFunctionJUnitTest method testExecuteOnMemberHavingANonGemFireCache.
@Test
public void testExecuteOnMemberHavingANonGemFireCache() throws Throwable {
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "FunctionContext");
final TestResultSender testResultSender = new TestResultSender();
mockContext.checking(new Expectations() {
{
exactly(0).of(mockFunctionContext).getResultSender();
will(returnValue(testResultSender));
}
});
final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache);
function.execute(mockFunctionContext);
final List<?> results = testResultSender.getResults();
assertNotNull(results);
assertTrue(results.isEmpty());
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class ListDiskStoresFunctionJUnitTest method testExecuteOnMemberHavingNoDiskStores.
@Test
@SuppressWarnings("unchecked")
public void testExecuteOnMemberHavingNoDiskStores() throws Throwable {
final InternalCache mockCache = mockContext.mock(InternalCache.class, "Cache");
final InternalDistributedMember mockMember = mockContext.mock(InternalDistributedMember.class, "DistributedMember");
final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "FunctionContext");
final TestResultSender testResultSender = new TestResultSender();
mockContext.checking(new Expectations() {
{
oneOf(mockCache).getMyId();
will(returnValue(mockMember));
oneOf(mockCache).listDiskStoresIncludingRegionOwned();
will(returnValue(Collections.emptyList()));
oneOf(mockFunctionContext).getResultSender();
will(returnValue(testResultSender));
}
});
final ListDiskStoresFunction function = createListDiskStoresFunction(mockCache);
function.execute(mockFunctionContext);
final List<?> results = testResultSender.getResults();
assertNotNull(results);
assertEquals(1, results.size());
final Set<DiskStoreDetails> diskStoreDetails = (Set<DiskStoreDetails>) results.get(0);
assertNotNull(diskStoreDetails);
assertTrue(diskStoreDetails.isEmpty());
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class ListDiskStoresFunctionJUnitTest method testExecute.
@Test
@SuppressWarnings("unchecked")
public void testExecute() throws Throwable {
final UUID mockDiskStoreOneId = UUID.randomUUID();
final UUID mockDiskStoreTwoId = UUID.randomUUID();
final UUID mockDiskStoreThreeId = UUID.randomUUID();
final String memberId = "mockMemberId";
final String memberName = "mockMemberName";
final InternalCache mockCache = mockContext.mock(InternalCache.class, "Cache");
final InternalDistributedMember mockMember = mockContext.mock(InternalDistributedMember.class, "DistributedMember");
final DiskStoreImpl mockDiskStoreOne = mockContext.mock(DiskStoreImpl.class, "DiskStoreOne");
final DiskStoreImpl mockDiskStoreTwo = mockContext.mock(DiskStoreImpl.class, "DiskStoreTwo");
final DiskStoreImpl mockDiskStoreThree = mockContext.mock(DiskStoreImpl.class, "DiskStoreThree");
final Collection<DiskStoreImpl> mockDiskStores = new ArrayList<DiskStoreImpl>();
mockDiskStores.add(mockDiskStoreOne);
mockDiskStores.add(mockDiskStoreTwo);
mockDiskStores.add(mockDiskStoreThree);
final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "FunctionContext");
final TestResultSender testResultSender = new TestResultSender();
mockContext.checking(new Expectations() {
{
oneOf(mockCache).getMyId();
will(returnValue(mockMember));
oneOf(mockCache).listDiskStoresIncludingRegionOwned();
will(returnValue(mockDiskStores));
exactly(3).of(mockMember).getId();
will(returnValue(memberId));
exactly(3).of(mockMember).getName();
will(returnValue(memberName));
oneOf(mockDiskStoreOne).getDiskStoreUUID();
will(returnValue(mockDiskStoreOneId));
oneOf(mockDiskStoreOne).getName();
will(returnValue("ds-backup"));
oneOf(mockDiskStoreTwo).getDiskStoreUUID();
will(returnValue(mockDiskStoreTwoId));
oneOf(mockDiskStoreTwo).getName();
will(returnValue("ds-overflow"));
oneOf(mockDiskStoreThree).getDiskStoreUUID();
will(returnValue(mockDiskStoreThreeId));
oneOf(mockDiskStoreThree).getName();
will(returnValue("ds-persistence"));
oneOf(mockFunctionContext).getResultSender();
will(returnValue(testResultSender));
}
});
final ListDiskStoresFunction function = createListDiskStoresFunction(mockCache);
function.execute(mockFunctionContext);
final List<?> results = testResultSender.getResults();
assertNotNull(results);
assertEquals(1, results.size());
final Set<DiskStoreDetails> diskStoreDetails = (Set<DiskStoreDetails>) results.get(0);
assertNotNull(diskStoreDetails);
assertEquals(3, diskStoreDetails.size());
diskStoreDetails.containsAll(Arrays.asList(createDiskStoreDetails(mockDiskStoreOneId, "ds-backup", memberId, memberName), createDiskStoreDetails(mockDiskStoreTwoId, "ds-overflow", memberId, memberName), createDiskStoreDetails(mockDiskStoreThreeId, "ds-persistence", memberId, memberName)));
}
Aggregations