use of org.apache.geode.internal.cache.execute.AbstractExecution in project geode by apache.
the class DiskStoreCommandsJUnitTest method testGetDiskStoreList.
@Test
public void testGetDiskStoreList() {
final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
final DistributedMember mockDistributedMember = mockContext.mock(DistributedMember.class, "DistributedMember");
final AbstractExecution mockFunctionExecutor = mockContext.mock(AbstractExecution.class, "Function Executor");
final ResultCollector mockResultCollector = mockContext.mock(ResultCollector.class, "ResultCollector");
final DiskStoreDetails diskStoreDetails1 = createDiskStoreDetails("memberOne", "cacheServerDiskStore");
final DiskStoreDetails diskStoreDetails2 = createDiskStoreDetails("memberOne", "gatewayDiskStore");
final DiskStoreDetails diskStoreDetails3 = createDiskStoreDetails("memberTwo", "pdxDiskStore");
final DiskStoreDetails diskStoreDetails4 = createDiskStoreDetails("memberTwo", "regionDiskStore");
final List<DiskStoreDetails> expectedDiskStores = Arrays.asList(diskStoreDetails1, diskStoreDetails2, diskStoreDetails3, diskStoreDetails4);
final List<Set<DiskStoreDetails>> results = new ArrayList<Set<DiskStoreDetails>>();
results.add(CollectionUtils.asSet(diskStoreDetails4, diskStoreDetails3));
results.add(CollectionUtils.asSet(diskStoreDetails1, diskStoreDetails2));
mockContext.checking(new Expectations() {
{
oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true)));
oneOf(mockFunctionExecutor).execute(with(aNonNull(ListDiskStoresFunction.class)));
will(returnValue(mockResultCollector));
oneOf(mockResultCollector).getResult();
will(returnValue(results));
}
});
final DiskStoreCommands commands = createDiskStoreCommands(mockCache, mockDistributedMember, mockFunctionExecutor);
final List<DiskStoreDetails> actualDiskStores = commands.getDiskStoreListing(commands.getNormalMembers(mockCache));
Assert.assertNotNull(actualDiskStores);
assertEquals(expectedDiskStores, actualDiskStores);
}
use of org.apache.geode.internal.cache.execute.AbstractExecution in project geode by apache.
the class DiskStoreCommandsJUnitTest method testGetDiskStoreListReturnsFunctionInvocationTargetExceptionInResults.
@Test
public void testGetDiskStoreListReturnsFunctionInvocationTargetExceptionInResults() {
final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
final DistributedMember mockDistributedMember = mockContext.mock(DistributedMember.class, "DistributedMember");
final AbstractExecution mockFunctionExecutor = mockContext.mock(AbstractExecution.class, "Function Executor");
final ResultCollector mockResultCollector = mockContext.mock(ResultCollector.class, "ResultCollector");
final DiskStoreDetails diskStoreDetails = createDiskStoreDetails("memberOne", "cacheServerDiskStore");
final List<DiskStoreDetails> expectedDiskStores = Arrays.asList(diskStoreDetails);
final List<Object> results = new ArrayList<Object>();
results.add(CollectionUtils.asSet(diskStoreDetails));
results.add(new FunctionInvocationTargetException("expected"));
mockContext.checking(new Expectations() {
{
oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true)));
oneOf(mockFunctionExecutor).execute(with(aNonNull(ListDiskStoresFunction.class)));
will(returnValue(mockResultCollector));
oneOf(mockResultCollector).getResult();
will(returnValue(results));
}
});
final DiskStoreCommands commands = createDiskStoreCommands(mockCache, mockDistributedMember, mockFunctionExecutor);
final List<DiskStoreDetails> actualDiskStores = commands.getDiskStoreListing(commands.getNormalMembers(mockCache));
Assert.assertNotNull(actualDiskStores);
assertEquals(expectedDiskStores, actualDiskStores);
}
use of org.apache.geode.internal.cache.execute.AbstractExecution in project geode by apache.
the class IndexCommandsJUnitTest method testGetIndexListingReturnsFunctionInvocationTargetExceptionInResults.
@Test
public void testGetIndexListingReturnsFunctionInvocationTargetExceptionInResults() {
final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
final AbstractExecution mockFunctionExecutor = mockContext.mock(AbstractExecution.class, "Function Executor");
final ResultCollector mockResultCollector = mockContext.mock(ResultCollector.class, "ResultCollector");
final IndexDetails indexDetails = createIndexDetails("memberOne", "/Employees", "empIdIdx");
final List<IndexDetails> expectedIndexDetails = Arrays.asList(indexDetails);
final List<Object> results = new ArrayList<Object>(2);
results.add(CollectionUtils.asSet(indexDetails));
results.add(new FunctionInvocationTargetException("expected"));
mockContext.checking(new Expectations() {
{
oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true)));
oneOf(mockFunctionExecutor).execute(with(aNonNull(ListIndexFunction.class)));
will(returnValue(mockResultCollector));
oneOf(mockResultCollector).getResult();
will(returnValue(results));
}
});
final IndexCommands commands = createIndexCommands(mockCache, mockFunctionExecutor);
final List<IndexDetails> actualIndexDetails = commands.getIndexListing();
assertNotNull(actualIndexDetails);
assertEquals(expectedIndexDetails, actualIndexDetails);
}
use of org.apache.geode.internal.cache.execute.AbstractExecution in project geode by apache.
the class IndexCommandsJUnitTest method testGetIndexListing.
@Test
public void testGetIndexListing() {
final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
final AbstractExecution mockFunctionExecutor = mockContext.mock(AbstractExecution.class, "Function Executor");
final ResultCollector mockResultCollector = mockContext.mock(ResultCollector.class, "ResultCollector");
final IndexDetails indexDetails1 = createIndexDetails("memberOne", "/Employees", "empIdIdx");
final IndexDetails indexDetails2 = createIndexDetails("memberOne", "/Employees", "empLastNameIdx");
final IndexDetails indexDetails3 = createIndexDetails("memberTwo", "/Employees", "empDobIdx");
final List<IndexDetails> expectedIndexDetails = Arrays.asList(indexDetails1, indexDetails2, indexDetails3);
final List<Set<IndexDetails>> results = new ArrayList<Set<IndexDetails>>(2);
results.add(CollectionUtils.asSet(indexDetails2, indexDetails1));
results.add(CollectionUtils.asSet(indexDetails3));
mockContext.checking(new Expectations() {
{
oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true)));
oneOf(mockFunctionExecutor).execute(with(aNonNull(ListIndexFunction.class)));
will(returnValue(mockResultCollector));
oneOf(mockResultCollector).getResult();
will(returnValue(results));
}
});
final IndexCommands commands = createIndexCommands(mockCache, mockFunctionExecutor);
final List<IndexDetails> actualIndexDetails = commands.getIndexListing();
assertNotNull(actualIndexDetails);
assertEquals(expectedIndexDetails, actualIndexDetails);
}
use of org.apache.geode.internal.cache.execute.AbstractExecution in project geode by apache.
the class LuceneIndexCommands method getIndexListing.
@SuppressWarnings("unchecked")
protected List<LuceneIndexDetails> getIndexListing() {
final Execution functionExecutor = getMembersFunctionExecutor(getMembers(getCache()));
if (functionExecutor instanceof AbstractExecution) {
((AbstractExecution) functionExecutor).setIgnoreDepartedMembers(true);
}
final ResultCollector resultsCollector = functionExecutor.execute(new LuceneListIndexFunction());
final List<Set<LuceneIndexDetails>> results = (List<Set<LuceneIndexDetails>>) resultsCollector.getResult();
List<LuceneIndexDetails> sortedResults = results.stream().flatMap(set -> set.stream()).sorted().collect(Collectors.toList());
LinkedHashSet<LuceneIndexDetails> uniqResults = new LinkedHashSet<>();
uniqResults.addAll(sortedResults);
sortedResults.clear();
sortedResults.addAll(uniqResults);
return sortedResults;
}
Aggregations