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);
}
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);
}
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);
}
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);
}
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;
}
}
Aggregations