use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class ListIndexFunctionJUnitTest method testExecute.
@Test
@SuppressWarnings("unchecked")
public void testExecute() throws Throwable {
final String memberId = "mockMemberId";
final String memberName = "mockMemberName";
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
final DistributedMember mockDistributedMember = mockContext.mock(DistributedMember.class, "DistributedMember");
final IndexDetails indexDetailsOne = createIndexDetails(memberId, "/Employees", "empIdIdx", IndexType.PRIMARY_KEY, "/Employees", "id", memberName, "id, firstName, lastName", "Employees");
indexDetailsOne.setIndexStatisticsDetails(createIndexStatisticsDetails(10124l, 4096l, 10124l, 1284100l, 280120l));
final IndexDetails indexDetailsTwo = createIndexDetails(memberId, "/Employees", "empGivenNameIdx", IndexType.FUNCTIONAL, "/Employees", "lastName", memberName, "id, firstName, lastName", "Employees");
final IndexDetails indexDetailsThree = createIndexDetails(memberId, "/Contractors", "empIdIdx", IndexType.PRIMARY_KEY, "/Contrators", "id", memberName, "id, firstName, lastName", "Contractors");
indexDetailsThree.setIndexStatisticsDetails(createIndexStatisticsDetails(1024l, 256l, 20248l, 768001l, 24480l));
final IndexDetails indexDetailsFour = createIndexDetails(memberId, "/Employees", "empIdIdx", IndexType.FUNCTIONAL, "/Employees", "emp_id", memberName, "id, surname, givenname", "Employees");
final Set<IndexDetails> expectedIndexDetailsSet = new HashSet<IndexDetails>(3);
expectedIndexDetailsSet.add(indexDetailsOne);
expectedIndexDetailsSet.add(indexDetailsTwo);
expectedIndexDetailsSet.add(indexDetailsThree);
final QueryService mockQueryService = mockContext.mock(QueryService.class, "QueryService");
final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "FunctionContext");
final TestResultSender testResultSender = new TestResultSender();
mockContext.checking(new Expectations() {
{
oneOf(mockCache).getDistributedSystem();
will(returnValue(mockDistributedSystem));
oneOf(mockCache).getQueryService();
will(returnValue(mockQueryService));
oneOf(mockDistributedSystem).getDistributedMember();
will(returnValue(mockDistributedMember));
exactly(4).of(mockDistributedMember).getId();
will(returnValue(memberId));
exactly(4).of(mockDistributedMember).getName();
will(returnValue(memberName));
oneOf(mockQueryService).getIndexes();
will(returnValue(Arrays.asList(createMockIndex(indexDetailsOne), createMockIndex(indexDetailsTwo), createMockIndex(indexDetailsThree), createMockIndex(indexDetailsFour))));
oneOf(mockFunctionContext).getResultSender();
will(returnValue(testResultSender));
}
});
final ListIndexFunction function = createListIndexFunction(mockCache);
function.execute(mockFunctionContext);
final List<?> results = testResultSender.getResults();
assertNotNull(results);
assertEquals(1, results.size());
final Set<IndexDetails> actualIndexDetailsSet = (Set<IndexDetails>) results.get(0);
assertNotNull(actualIndexDetailsSet);
assertEquals(expectedIndexDetailsSet.size(), actualIndexDetailsSet.size());
for (final IndexDetails expectedIndexDetails : expectedIndexDetailsSet) {
final IndexDetails actualIndexDetails = CollectionUtils.findBy(actualIndexDetailsSet, new Filter<IndexDetails>() {
@Override
public boolean accept(final IndexDetails indexDetails) {
return ObjectUtils.equals(expectedIndexDetails, indexDetails);
}
});
assertNotNull(actualIndexDetails);
assertIndexDetailsEquals(expectedIndexDetails, actualIndexDetails);
}
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class ListIndexFunctionJUnitTest method testExecuteWithNoIndexes.
@Test
@SuppressWarnings("unchecked")
public void testExecuteWithNoIndexes() throws Throwable {
final Cache mockCache = mockContext.mock(Cache.class, "Cache");
final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
final DistributedMember mockDistributedMember = mockContext.mock(DistributedMember.class, "DistributedMember");
final QueryService mockQueryService = mockContext.mock(QueryService.class, "QueryService");
final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "FunctionContext");
final TestResultSender testResultSender = new TestResultSender();
mockContext.checking(new Expectations() {
{
oneOf(mockCache).getDistributedSystem();
will(returnValue(mockDistributedSystem));
oneOf(mockCache).getQueryService();
will(returnValue(mockQueryService));
oneOf(mockDistributedSystem).getDistributedMember();
will(returnValue(mockDistributedMember));
oneOf(mockQueryService).getIndexes();
will(returnValue(Collections.emptyList()));
oneOf(mockFunctionContext).getResultSender();
will(returnValue(testResultSender));
}
});
final ListIndexFunction function = createListIndexFunction(mockCache);
function.execute(mockFunctionContext);
final List<?> results = testResultSender.getResults();
assertNotNull(results);
assertEquals(1, results.size());
final Set<IndexDetails> actualIndexDetailsSet = (Set<IndexDetails>) results.get(0);
assertNotNull(actualIndexDetailsSet);
assertTrue(actualIndexDetailsSet.isEmpty());
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class DescribeDiskStoreFunctionJUnitTest method testExecuteThrowingDiskStoreNotFoundException.
@Test
public void testExecuteThrowingDiskStoreNotFoundException() throws Exception {
final String diskStoreName = "testDiskStore";
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 FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "FunctionContext");
final TestResultSender testResultSender = new TestResultSender();
mockContext.checking(new Expectations() {
{
oneOf(mockCache).getMyId();
will(returnValue(mockMember));
oneOf(mockCache).findDiskStore(diskStoreName);
will(returnValue(null));
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 DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache);
function.execute(mockFunctionContext);
String expected = String.format("A disk store with name (%1$s) was not found on member (%2$s).", diskStoreName, memberName);
assertThatThrownBy(() -> testResultSender.getResults()).isInstanceOf(DiskStoreNotFoundException.class).hasMessage(expected);
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class DescribeDiskStoreFunctionJUnitTest method doTestExecuteWithDiskDirsAndDiskSizesMismatch.
private void doTestExecuteWithDiskDirsAndDiskSizesMismatch() throws Exception {
final String diskStoreName = "mockDiskStore";
final String memberId = "mockMemberId";
final String memberName = "mockMemberName";
final UUID diskStoreId = UUID.randomUUID();
final InternalCache mockCache = mockContext.mock(InternalCache.class, "Cache");
final InternalDistributedMember mockMember = mockContext.mock(InternalDistributedMember.class, "DistributedMember");
final DiskStore mockDiskStore = createMockDiskStore(diskStoreId, diskStoreName, false, true, 70, 8192000l, 1000, 300l, 8192, createFileArray("/export/disk0/gemfire/backup"), new int[0], 50, 75);
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).findDiskStore(diskStoreName);
will(returnValue(mockDiskStore));
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 DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(mockCache);
function.execute(mockFunctionContext);
String expected = "The number of disk directories with a specified size (0) does not match the number of disk directories (1)!";
assertThatThrownBy(() -> testResultSender.getResults()).hasMessage(expected);
}
use of org.apache.geode.cache.execute.FunctionContext in project geode by apache.
the class ListDiskStoresFunctionJUnitTest method testExecuteOnMemberWithNoCache.
@Test(expected = CacheClosedException.class)
public void testExecuteOnMemberWithNoCache() throws Throwable {
final FunctionContext mockFunctionContext = mockContext.mock(FunctionContext.class, "MockFunctionContext");
final ListDiskStoresFunction testListDiskStoresFunction = new TestListDiskStoresFunction(mockContext.mock(Cache.class, "MockCache")) {
@Override
protected Cache getCache() {
throw new CacheClosedException("Expected");
}
};
final TestResultSender testResultSender = new TestResultSender();
mockContext.checking(new Expectations() {
{
oneOf(mockFunctionContext).getResultSender();
will(returnValue(testResultSender));
}
});
testListDiskStoresFunction.execute(mockFunctionContext);
try {
testResultSender.getResults();
} catch (CacheClosedException expected) {
assertEquals("Expected", expected.getMessage());
throw expected;
}
}
Aggregations