Search in sources :

Example 6 with AbstractExecution

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);
}
Also used : Expectations(org.jmock.Expectations) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) Set(java.util.Set) ListDiskStoresFunction(org.apache.geode.management.internal.cli.functions.ListDiskStoresFunction) DistributedMember(org.apache.geode.distributed.DistributedMember) DiskStoreDetails(org.apache.geode.management.internal.cli.domain.DiskStoreDetails) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) ResultCollector(org.apache.geode.cache.execute.ResultCollector) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 7 with AbstractExecution

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);
}
Also used : Expectations(org.jmock.Expectations) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) ListDiskStoresFunction(org.apache.geode.management.internal.cli.functions.ListDiskStoresFunction) DiskStoreDetails(org.apache.geode.management.internal.cli.domain.DiskStoreDetails) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) DistributedMember(org.apache.geode.distributed.DistributedMember) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ResultCollector(org.apache.geode.cache.execute.ResultCollector) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 8 with AbstractExecution

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);
}
Also used : Expectations(org.jmock.Expectations) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) ArrayList(java.util.ArrayList) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) InternalCache(org.apache.geode.internal.cache.InternalCache) IndexDetails(org.apache.geode.management.internal.cli.domain.IndexDetails) ResultCollector(org.apache.geode.cache.execute.ResultCollector) ListIndexFunction(org.apache.geode.management.internal.cli.functions.ListIndexFunction) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 9 with AbstractExecution

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);
}
Also used : Expectations(org.jmock.Expectations) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) Set(java.util.Set) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) IndexDetails(org.apache.geode.management.internal.cli.domain.IndexDetails) ResultCollector(org.apache.geode.cache.execute.ResultCollector) ListIndexFunction(org.apache.geode.management.internal.cli.functions.ListIndexFunction) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 10 with AbstractExecution

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) Execution(org.apache.geode.cache.execute.Execution) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LuceneListIndexFunction(org.apache.geode.cache.lucene.internal.cli.functions.LuceneListIndexFunction) ArrayList(java.util.ArrayList) List(java.util.List) ResultCollector(org.apache.geode.cache.execute.ResultCollector)

Aggregations

AbstractExecution (org.apache.geode.internal.cache.execute.AbstractExecution)19 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)11 Set (java.util.Set)10 Execution (org.apache.geode.cache.execute.Execution)8 ResultCollector (org.apache.geode.cache.execute.ResultCollector)8 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)6 InternalCache (org.apache.geode.internal.cache.InternalCache)6 UnitTest (org.apache.geode.test.junit.categories.UnitTest)6 IOException (java.io.IOException)5 Region (org.apache.geode.cache.Region)5 Function (org.apache.geode.cache.execute.Function)5 FunctionException (org.apache.geode.cache.execute.FunctionException)5 ExecuteFunctionOperationContext (org.apache.geode.cache.operations.ExecuteFunctionOperationContext)5 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)5 InternalFunctionInvocationTargetException (org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException)5 MemberMappedArgument (org.apache.geode.internal.cache.execute.MemberMappedArgument)5 PartitionedRegionFunctionExecutor (org.apache.geode.internal.cache.execute.PartitionedRegionFunctionExecutor)5 ServerToClientFunctionResultSender (org.apache.geode.internal.cache.execute.ServerToClientFunctionResultSender)5 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)5