Search in sources :

Example 61 with DistributedMember

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

the class ExportLogsCommandTest method sizeOKOnMember_sizeChecksEnabled_doesNotThrow.

@Test
public void sizeOKOnMember_sizeChecksEnabled_doesNotThrow() throws Exception {
    final Cache mockCache = mock(Cache.class);
    final DistributedMember mockDistributedMember = mock(DistributedMember.class);
    final Execution mockFunctionExecutor = mock(Execution.class);
    final ExportLogsCommand cmd = createExportLogsCommand(mockCache, mockDistributedMember, mockFunctionExecutor);
    cmd.checkIfExportLogsOverflowsDisk("clusterMember", 10 * MEGABYTE, MEGABYTE - 1024, MEGABYTE);
}
Also used : Execution(org.apache.geode.cache.execute.Execution) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) ExportLogsCommand(org.apache.geode.management.internal.cli.commands.ExportLogsCommand) InternalCache(org.apache.geode.internal.cache.InternalCache) Cache(org.apache.geode.cache.Cache) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 62 with DistributedMember

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

the class ExportLogsCommandTest method sizeFromAllMembers_greaterThanLocalDiskAvailable_shouldReturnErrorResult.

@Test
public void sizeFromAllMembers_greaterThanLocalDiskAvailable_shouldReturnErrorResult() throws Exception {
    final InternalCache mockCache = mock(InternalCache.class);
    final ExportLogsCommand realCmd = new ExportLogsCommand();
    ExportLogsCommand spyCmd = spy(realCmd);
    String start = null;
    String end = null;
    String logLevel = null;
    boolean onlyLogLevel = false;
    boolean logsOnly = false;
    boolean statsOnly = false;
    InternalDistributedMember member1 = new InternalDistributedMember("member1", 12345);
    InternalDistributedMember member2 = new InternalDistributedMember("member2", 98765);
    member1.getNetMember().setName("member1");
    member2.getNetMember().setName("member2");
    Set<DistributedMember> testMembers = new HashSet<>();
    testMembers.add(member1);
    testMembers.add(member2);
    ResultCollector testResults1 = new CustomCollector();
    testResults1.addResult(member1, Arrays.asList(75 * MEGABYTE));
    ResultCollector testResults2 = new CustomCollector();
    testResults2.addResult(member2, Arrays.asList(60 * MEGABYTE));
    doReturn(mockCache).when(spyCmd).getCache();
    doReturn(testMembers).when(spyCmd).getMembers(null, null);
    doReturn(testResults1).when(spyCmd).estimateLogSize(Matchers.any(SizeExportLogsFunction.Args.class), eq(member1));
    doReturn(testResults2).when(spyCmd).estimateLogSize(Matchers.any(SizeExportLogsFunction.Args.class), eq(member2));
    doReturn(125 * MEGABYTE).when(spyCmd).getLocalDiskAvailable();
    doReturn(GIGABYTE).when(spyCmd).getLocalDiskSize();
    Result res = spyCmd.exportLogs("working dir", null, null, logLevel, onlyLogLevel, false, start, end, logsOnly, statsOnly, "125m");
    assertThat(res.getStatus()).isEqualTo(Result.Status.ERROR);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) ExportLogsCommand(org.apache.geode.management.internal.cli.commands.ExportLogsCommand) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet) Result(org.apache.geode.management.cli.Result) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 63 with DistributedMember

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

the class DiskStoreCommandsJUnitTest method testGetDiskStoreDescription.

@Test
public void testGetDiskStoreDescription() {
    final String diskStoreName = "mockDiskStore";
    final String memberId = "mockMember";
    final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
    final DistributedMember mockMember = mockContext.mock(DistributedMember.class, "DistributedMember");
    final Execution mockFunctionExecutor = mockContext.mock(Execution.class, "Function Executor");
    final ResultCollector mockResultCollector = mockContext.mock(ResultCollector.class, "ResultCollector");
    final DiskStoreDetails expectedDiskStoredDetails = createDiskStoreDetails(memberId, diskStoreName);
    mockContext.checking(new Expectations() {

        {
            oneOf(mockMember).getName();
            will(returnValue(null));
            oneOf(mockMember).getId();
            will(returnValue(memberId));
            oneOf(mockFunctionExecutor).setArguments(with(equal(diskStoreName)));
            will(returnValue(mockFunctionExecutor));
            oneOf(mockFunctionExecutor).execute(with(aNonNull(DescribeDiskStoreFunction.class)));
            will(returnValue(mockResultCollector));
            oneOf(mockResultCollector).getResult();
            will(returnValue(Arrays.asList(expectedDiskStoredDetails)));
        }
    });
    final DiskStoreCommands commands = createDiskStoreCommands(mockCache, mockMember, mockFunctionExecutor);
    final DiskStoreDetails actualDiskStoreDetails = commands.getDiskStoreDescription(memberId, diskStoreName);
    assertNotNull(actualDiskStoreDetails);
    assertEquals(expectedDiskStoredDetails, actualDiskStoreDetails);
}
Also used : Expectations(org.jmock.Expectations) Execution(org.apache.geode.cache.execute.Execution) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) DistributedMember(org.apache.geode.distributed.DistributedMember) DiskStoreDetails(org.apache.geode.management.internal.cli.domain.DiskStoreDetails) InternalCache(org.apache.geode.internal.cache.InternalCache) ResultCollector(org.apache.geode.cache.execute.ResultCollector) DescribeDiskStoreFunction(org.apache.geode.management.internal.cli.functions.DescribeDiskStoreFunction) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 64 with DistributedMember

use of org.apache.geode.distributed.DistributedMember 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 65 with DistributedMember

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

the class DiskStoreCommandsJUnitTest method testGetDiskStoreDescriptionThrowsMemberNotFoundException.

@Test(expected = MemberNotFoundException.class)
public void testGetDiskStoreDescriptionThrowsMemberNotFoundException() {
    final String diskStoreName = "mockDiskStore";
    final String memberId = "mockMember";
    final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
    final DistributedMember mockMember = mockContext.mock(DistributedMember.class, "DistributedMember");
    mockContext.checking(new Expectations() {

        {
            oneOf(mockMember).getName();
            will(returnValue(null));
            oneOf(mockMember).getId();
            will(returnValue("testMember"));
        }
    });
    final DiskStoreCommands commands = createDiskStoreCommands(mockCache, mockMember, null);
    try {
        commands.getDiskStoreDescription(memberId, diskStoreName);
    } catch (MemberNotFoundException expected) {
        assertEquals(CliStrings.format(CliStrings.MEMBER_NOT_FOUND_ERROR_MESSAGE, memberId), expected.getMessage());
        throw expected;
    }
}
Also used : Expectations(org.jmock.Expectations) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalCache(org.apache.geode.internal.cache.InternalCache) MemberNotFoundException(org.apache.geode.management.internal.cli.util.MemberNotFoundException) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

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