Search in sources :

Example 41 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class GemfireDataCommandsDUnitTest method testRegionsViaMbeanAndFunctions.

@Test
public void testRegionsViaMbeanAndFunctions() {
    setupForGetPutRemoveLocateEntry("tesSimplePut");
    waitForListClientMbean(DATA_REGION_NAME_PATH);
    final VM manager = Host.getHost(0).getVM(0);
    String memSizeFromMbean = (String) manager.invoke(new SerializableCallable() {

        public Object call() {
            Cache cache = GemFireCacheImpl.getInstance();
            DistributedRegionMXBean bean = ManagementService.getManagementService(cache).getDistributedRegionMXBean(DATA_REGION_NAME_PATH);
            if (// try with slash ahead
            bean == null)
                bean = ManagementService.getManagementService(cache).getDistributedRegionMXBean(Region.SEPARATOR + DATA_REGION_NAME_PATH);
            if (bean == null) {
                return null;
            }
            String[] membersName = bean.getMembers();
            return "" + membersName.length;
        }
    });
    getLogWriter().info("testRegionsViaMbeanAndFunctions memSizeFromMbean= " + memSizeFromMbean);
    String memSizeFromFunctionCall = (String) manager.invoke(new SerializableCallable() {

        public Object call() {
            InternalCache cache = GemFireCacheImpl.getInstance();
            CliUtil.getMembersForeRegionViaFunction(cache, DATA_REGION_NAME_PATH, true);
            return "" + CliUtil.getMembersForeRegionViaFunction(cache, DATA_REGION_NAME_PATH, true).size();
        }
    });
    getLogWriter().info("testRegionsViaMbeanAndFunctions memSizeFromFunctionCall= " + memSizeFromFunctionCall);
    assertTrue(memSizeFromFunctionCall.equals(memSizeFromMbean));
}
Also used : VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) InternalCache(org.apache.geode.internal.cache.InternalCache) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 42 with InternalCache

use of org.apache.geode.internal.cache.InternalCache 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 43 with InternalCache

use of org.apache.geode.internal.cache.InternalCache 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 44 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class GfshCommandJUnitTest method testGetMemberWithMatchingMemberNameCaseInsensitive.

@Test
public void testGetMemberWithMatchingMemberNameCaseInsensitive() {
    final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
    final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
    final DistributedMember mockMemberSelf = createMockMember("S", "Self");
    final DistributedMember mockMemberOne = createMockMember("1", "One");
    final DistributedMember mockMemberTwo = createMockMember("2", "Two");
    mockContext.checking(new Expectations() {

        {
            oneOf(mockCache).getMembers();
            will(returnValue(CollectionUtils.asSet(mockMemberOne, mockMemberTwo)));
            oneOf(mockCache).getDistributedSystem();
            will(returnValue(mockDistributedSystem));
            oneOf(mockDistributedSystem).getDistributedMember();
            will(returnValue(mockMemberSelf));
        }
    });
    final GfshCommand commands = createAbstractCommandsSupport(mockCache);
    assertSame(mockMemberSelf, commands.getMember(mockCache, "self"));
}
Also used : Expectations(org.jmock.Expectations) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) DistributedSystem(org.apache.geode.distributed.DistributedSystem) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 45 with InternalCache

use of org.apache.geode.internal.cache.InternalCache in project geode by apache.

the class GfshCommandJUnitTest method testGetMembers.

@Test
public void testGetMembers() {
    final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
    final DistributedSystem mockDistributedSystem = mockContext.mock(DistributedSystem.class, "DistributedSystem");
    final DistributedMember mockMemberSelf = createMockMember("S", "Self");
    final DistributedMember mockMemberOne = createMockMember("1", "One");
    final DistributedMember mockMemberTwo = createMockMember("2", "Two");
    mockContext.checking(new Expectations() {

        {
            oneOf(mockCache).getMembers();
            will(returnValue(CollectionUtils.asSet(mockMemberOne, mockMemberTwo)));
            oneOf(mockCache).getDistributedSystem();
            will(returnValue(mockDistributedSystem));
            oneOf(mockDistributedSystem).getDistributedMember();
            will(returnValue(mockMemberSelf));
        }
    });
    final GfshCommand commands = createAbstractCommandsSupport(mockCache);
    final Set<DistributedMember> expectedMembers = CollectionUtils.asSet(mockMemberOne, mockMemberTwo, mockMemberSelf);
    final Set<DistributedMember> actualMembers = commands.getMembers(mockCache);
    assertNotNull(actualMembers);
    assertEquals(expectedMembers.size(), actualMembers.size());
    assertTrue(actualMembers.containsAll(expectedMembers));
}
Also used : Expectations(org.jmock.Expectations) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) DistributedSystem(org.apache.geode.distributed.DistributedSystem) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

InternalCache (org.apache.geode.internal.cache.InternalCache)267 DistributedMember (org.apache.geode.distributed.DistributedMember)78 Test (org.junit.Test)64 UnitTest (org.apache.geode.test.junit.categories.UnitTest)52 IOException (java.io.IOException)48 ArrayList (java.util.ArrayList)35 HashSet (java.util.HashSet)35 CliMetaData (org.apache.geode.management.cli.CliMetaData)34 CliCommand (org.springframework.shell.core.annotation.CliCommand)34 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)32 Region (org.apache.geode.cache.Region)31 Result (org.apache.geode.management.cli.Result)30 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)30 Expectations (org.jmock.Expectations)30 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)26 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)25 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)24 Set (java.util.Set)23 ResultCollector (org.apache.geode.cache.execute.ResultCollector)22 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)20