Search in sources :

Example 96 with DistributedMember

use of org.apache.geode.distributed.DistributedMember in project geode by apache.

the class CliUtilDUnitTest method getRegionAssociatedMembers.

public void getRegionAssociatedMembers() {
    String region_group1 = "/region_group1";
    String region1 = "/region1";
    String region_member2_group1 = "/region_member2_group1";
    InternalCache cache = getCache();
    Set<DistributedMember> set = CliUtil.getRegionAssociatedMembers(region1, cache, true);
    assertNotNull(set);
    assertEquals(4, set.size());
    assertEquals(true, containsMember(set, MEMBER_1_GROUP1));
    assertEquals(true, containsMember(set, MEMBER_2_GROUP1));
    assertEquals(true, containsMember(set, MEMBER_1_GROUP2));
    assertEquals(true, containsMember(set, MEMBER_2_GROUP2));
    /*
     * TODO: This is failing because last param is not considered in method set =
     * CliUtil.getRegionAssociatedMembers(region1, cache, false); assertNotNull(set);
     * assertIndexDetailsEquals(1, set.size());
     */
    set = CliUtil.getRegionAssociatedMembers(region_group1, cache, true);
    assertNotNull(set);
    assertEquals(2, set.size());
    assertEquals(true, containsMember(set, MEMBER_1_GROUP1));
    assertEquals(true, containsMember(set, MEMBER_2_GROUP1));
    set = CliUtil.getRegionAssociatedMembers(region_member2_group1, cache, true);
    assertNotNull(set);
    assertEquals(1, set.size());
    assertEquals(true, containsMember(set, MEMBER_2_GROUP1));
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache)

Example 97 with DistributedMember

use of org.apache.geode.distributed.DistributedMember in project geode by apache.

the class CliUtilDUnitTest method getDistributedMemberByNameOrId.

public void getDistributedMemberByNameOrId(String name, String id) {
    DistributedMember member = CliUtil.getDistributedMemberByNameOrId(name);
    assertNotNull(member);
    member = CliUtil.getDistributedMemberByNameOrId(id);
    assertNotNull(member);
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember)

Example 98 with DistributedMember

use of org.apache.geode.distributed.DistributedMember in project geode by apache.

the class ShowMetricsDUnitTest method testShowMetricsRegionFromMember.

@Test
public void testShowMetricsRegionFromMember() throws ClassNotFoundException, IOException, InterruptedException {
    systemSetUp();
    Cache cache = getCache();
    final DistributedMember distributedMember = cache.getDistributedSystem().getDistributedMember();
    final String exportFileName = "regionOnAMemberReport.csv";
    final String regionName = "REGION1";
    SerializableCallable showMetricCmd = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            WaitCriterion wc = createMBeanWaitCriterion(4, regionName, distributedMember, 0);
            waitForCriterion(wc, 5000, 500, true);
            CommandProcessor commandProcessor = new CommandProcessor();
            Result result = commandProcessor.createCommandStatement("show metrics --region=" + regionName + " --member=" + distributedMember.getName() + " --file=" + exportFileName, Collections.EMPTY_MAP).process();
            String resultAsString = commandResultToString((CommandResult) result);
            assertEquals(resultAsString, true, result.getStatus().equals(Status.OK));
            assertTrue(result.hasIncomingFiles());
            result.saveIncomingFiles(null);
            File file = new File(exportFileName);
            file.deleteOnExit();
            assertTrue(file.exists());
            file.delete();
            return resultAsString;
        }
    };
    // Invoke the command in the Manager VM
    final VM managerVm = Host.getHost(0).getVM(0);
    Object managerResultObj = managerVm.invoke(showMetricCmd);
    String managerResult = (String) managerResultObj;
    getLogWriter().info("#SB Manager");
    getLogWriter().info(managerResult);
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) CommandProcessor(org.apache.geode.management.internal.cli.remote.CommandProcessor) File(java.io.File) Cache(org.apache.geode.cache.Cache) Result(org.apache.geode.management.cli.Result) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 99 with DistributedMember

use of org.apache.geode.distributed.DistributedMember in project geode by apache.

the class ListIndexFunctionJUnitTest method testExecuteThrowsException.

@Test(expected = RuntimeException.class)
public void testExecuteThrowsException() 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(throwException(new RuntimeException("expected")));
            oneOf(mockFunctionContext).getResultSender();
            will(returnValue(testResultSender));
        }
    });
    final ListIndexFunction function = createListIndexFunction(mockCache);
    function.execute(mockFunctionContext);
    try {
        testResultSender.getResults();
    } catch (Throwable t) {
        assertTrue(t instanceof RuntimeException);
        assertEquals("expected", t.getMessage());
        throw t;
    }
}
Also used : Expectations(org.jmock.Expectations) QueryService(org.apache.geode.cache.query.QueryService) DistributedMember(org.apache.geode.distributed.DistributedMember) 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)

Example 100 with DistributedMember

use of org.apache.geode.distributed.DistributedMember in project geode by apache.

the class ShowMetricsDUnitTest method testShowMetricsMember.

// GEODE-1764
@Category(FlakyTest.class)
@Test
public void testShowMetricsMember() throws ClassNotFoundException, IOException, InterruptedException {
    systemSetUp();
    Cache cache = getCache();
    final DistributedMember distributedMember = cache.getDistributedSystem().getDistributedMember();
    final String exportFileName = "memberMetricReport.csv";
    int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(1);
    CacheServer cs = getCache().addCacheServer();
    cs.setPort(ports[0]);
    cs.start();
    final int cacheServerPort = cs.getPort();
    SerializableCallable showMetricCmd = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            WaitCriterion wc = createMBeanWaitCriterion(3, "", distributedMember, 0);
            waitForCriterion(wc, 5000, 500, true);
            wc = createMBeanWaitCriterion(5, "", distributedMember, cacheServerPort);
            waitForCriterion(wc, 10000, 500, true);
            final String command = CliStrings.SHOW_METRICS + " --" + CliStrings.SHOW_METRICS__MEMBER + "=" + distributedMember.getId() + " --" + CliStrings.SHOW_METRICS__CACHESERVER__PORT + "=" + cacheServerPort + " --" + CliStrings.SHOW_METRICS__FILE + "=" + exportFileName;
            CommandProcessor commandProcessor = new CommandProcessor();
            Result result = commandProcessor.createCommandStatement(command, Collections.EMPTY_MAP).process();
            String resultAsString = commandResultToString((CommandResult) result);
            assertEquals(resultAsString, true, result.getStatus().equals(Status.OK));
            assertTrue(result.hasIncomingFiles());
            result.saveIncomingFiles(null);
            File file = new File(exportFileName);
            file.deleteOnExit();
            assertTrue(file.exists());
            file.delete();
            return resultAsString;
        }
    };
    // Invoke the command in the Manager VM
    final VM managerVm = Host.getHost(0).getVM(0);
    Object managerResultObj = managerVm.invoke(showMetricCmd);
    String managerResult = (String) managerResultObj;
    getLogWriter().info("#SB Manager");
    getLogWriter().info(managerResult);
    cs.stop();
}
Also used : Result(org.apache.geode.management.cli.Result) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedMember(org.apache.geode.distributed.DistributedMember) CacheServer(org.apache.geode.cache.server.CacheServer) CommandProcessor(org.apache.geode.management.internal.cli.remote.CommandProcessor) File(java.io.File) Cache(org.apache.geode.cache.Cache) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

DistributedMember (org.apache.geode.distributed.DistributedMember)360 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)120 Test (org.junit.Test)109 HashSet (java.util.HashSet)83 InternalCache (org.apache.geode.internal.cache.InternalCache)83 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)82 ArrayList (java.util.ArrayList)64 VM (org.apache.geode.test.dunit.VM)60 CliCommand (org.springframework.shell.core.annotation.CliCommand)59 CliMetaData (org.apache.geode.management.cli.CliMetaData)57 Result (org.apache.geode.management.cli.Result)56 Set (java.util.Set)49 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)49 List (java.util.List)48 Cache (org.apache.geode.cache.Cache)47 Region (org.apache.geode.cache.Region)42 HashMap (java.util.HashMap)39 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)39 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)39 FunctionException (org.apache.geode.cache.execute.FunctionException)37