Search in sources :

Example 6 with IndexDetails

use of org.apache.geode.management.internal.cli.domain.IndexDetails in project geode by apache.

the class IndexCommands method getIndexListing.

@SuppressWarnings("unchecked")
protected List<IndexDetails> getIndexListing() {
    final Execution functionExecutor = getMembersFunctionExecutor(getMembers(getCache()));
    if (functionExecutor instanceof AbstractExecution) {
        ((AbstractExecution) functionExecutor).setIgnoreDepartedMembers(true);
    }
    final ResultCollector<?, ?> resultsCollector = functionExecutor.execute(new ListIndexFunction());
    final List<?> results = (List<?>) resultsCollector.getResult();
    final List<IndexDetails> indexDetailsList = new ArrayList<IndexDetails>(results.size());
    for (Object result : results) {
        if (result instanceof Set) {
            // ignore FunctionInvocationTargetExceptions and other Exceptions
            indexDetailsList.addAll((Set<IndexDetails>) result);
        }
    }
    Collections.sort(indexDetailsList);
    return indexDetailsList;
}
Also used : AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) Execution(org.apache.geode.cache.execute.Execution) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IndexDetails(org.apache.geode.management.internal.cli.domain.IndexDetails) ListIndexFunction(org.apache.geode.management.internal.cli.functions.ListIndexFunction)

Example 7 with IndexDetails

use of org.apache.geode.management.internal.cli.domain.IndexDetails 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);
    }
}
Also used : Expectations(org.jmock.Expectations) HashSet(java.util.HashSet) Set(java.util.Set) IndexDetails(org.apache.geode.management.internal.cli.domain.IndexDetails) DistributedSystem(org.apache.geode.distributed.DistributedSystem) FunctionContext(org.apache.geode.cache.execute.FunctionContext) QueryService(org.apache.geode.cache.query.QueryService) DistributedMember(org.apache.geode.distributed.DistributedMember) Cache(org.apache.geode.cache.Cache) HashSet(java.util.HashSet) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 8 with IndexDetails

use of org.apache.geode.management.internal.cli.domain.IndexDetails 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());
}
Also used : Expectations(org.jmock.Expectations) HashSet(java.util.HashSet) Set(java.util.Set) QueryService(org.apache.geode.cache.query.QueryService) DistributedMember(org.apache.geode.distributed.DistributedMember) IndexDetails(org.apache.geode.management.internal.cli.domain.IndexDetails) DistributedSystem(org.apache.geode.distributed.DistributedSystem) FunctionContext(org.apache.geode.cache.execute.FunctionContext) Cache(org.apache.geode.cache.Cache) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

IndexDetails (org.apache.geode.management.internal.cli.domain.IndexDetails)8 HashSet (java.util.HashSet)4 Set (java.util.Set)4 UnitTest (org.apache.geode.test.junit.categories.UnitTest)4 Expectations (org.jmock.Expectations)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Cache (org.apache.geode.cache.Cache)3 DistributedMember (org.apache.geode.distributed.DistributedMember)3 AbstractExecution (org.apache.geode.internal.cache.execute.AbstractExecution)3 ListIndexFunction (org.apache.geode.management.internal.cli.functions.ListIndexFunction)3 FunctionContext (org.apache.geode.cache.execute.FunctionContext)2 ResultCollector (org.apache.geode.cache.execute.ResultCollector)2 QueryService (org.apache.geode.cache.query.QueryService)2 DistributedSystem (org.apache.geode.distributed.DistributedSystem)2 InternalCache (org.apache.geode.internal.cache.InternalCache)2 List (java.util.List)1 TreeSet (java.util.TreeSet)1 Execution (org.apache.geode.cache.execute.Execution)1 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)1