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