use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest method FunctionExecution_Inline_Bug40714.
public static void FunctionExecution_Inline_Bug40714() {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 10); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
int j = 0;
for (Iterator i = testKeysSet.iterator(); i.hasNext(); ) {
Integer val = new Integer(j++);
region.put(i.next(), val);
}
HashMap resultMap = (HashMap) FunctionService.onRegion(region).setArguments(Boolean.TRUE).execute(new FunctionAdapter() {
public void execute(FunctionContext context) {
if (context.getArguments() instanceof String) {
context.getResultSender().lastResult("Success");
} else if (context.getArguments() instanceof Boolean) {
context.getResultSender().lastResult(Boolean.TRUE);
}
}
public String getId() {
return "Function";
}
public boolean hasResult() {
return true;
}
}).getResult();
assertEquals(3, resultMap.size());
Iterator mapIterator = resultMap.entrySet().iterator();
Map.Entry entry = null;
DistributedMember key = null;
ArrayList resultListForMember = null;
while (mapIterator.hasNext()) {
entry = (Map.Entry) mapIterator.next();
key = (DistributedMember) entry.getKey();
resultListForMember = (ArrayList) entry.getValue();
for (Object result : resultListForMember) {
assertEquals(Boolean.TRUE, result);
}
}
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class PRClientServerRegionFunctionExecutionSelectorNoSingleHopDUnitTest method executeFunction.
public static void executeFunction() throws ServerException, InterruptedException {
Region region = cache.getRegion(PartitionedRegionName);
assertNotNull(region);
final HashSet testKeysSet = new HashSet();
for (int i = (totalNumBuckets.intValue() * 10); i > 0; i--) {
testKeysSet.add("execKey-" + i);
}
DistributedSystem.setThreadsSocketPolicy(false);
Function function = new TestFunction(true, TEST_FUNCTION2);
FunctionService.registerFunction(function);
Execution dataSet = FunctionService.onRegion(region);
try {
ResultCollector rc1 = dataSet.withFilter(testKeysSet).setArguments(Boolean.TRUE).execute(function.getId());
HashMap resultMap = ((HashMap) rc1.getResult());
assertEquals(3, resultMap.size());
Iterator mapIterator = resultMap.entrySet().iterator();
Map.Entry entry = null;
DistributedMember key = null;
ArrayList resultListForMember = null;
while (mapIterator.hasNext()) {
entry = (Map.Entry) mapIterator.next();
key = (DistributedMember) entry.getKey();
resultListForMember = (ArrayList) entry.getValue();
for (Object result : resultListForMember) {
assertEquals(Boolean.TRUE, result);
}
}
} catch (Exception e) {
LogWriterUtils.getLogWriter().info("Got an exception : " + e.getMessage());
assertTrue(e instanceof EOFException || e instanceof SocketException || e instanceof SocketTimeoutException || e instanceof ServerException || e instanceof IOException || e instanceof CacheClosedException);
}
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class RollingUpgrade2DUnitTest method doTestVerifyXmlEntity.
private void doTestVerifyXmlEntity(String oldVersion) throws Exception {
final Host host = Host.getHost(0);
VM oldLocator = host.getVM(oldVersion, 0);
VM oldServer = host.getVM(oldVersion, 1);
VM currentServer1 = host.getVM(2);
VM currentServer2 = host.getVM(3);
int[] locatorPorts = AvailablePortHelper.getRandomAvailableTCPPorts(1);
String hostName = NetworkUtils.getServerHostName(host);
String locatorsString = getLocatorString(locatorPorts);
DistributedTestUtils.deleteLocatorStateFile(locatorPorts);
try {
// Start locator
oldLocator.invoke(invokeStartLocator(hostName, locatorPorts[0], getTestMethodName(), getLocatorPropertiesPre91(locatorsString)));
// Start servers
invokeRunnableInVMs(invokeCreateCache(getSystemProperties(locatorPorts)), oldServer, currentServer1, currentServer2);
currentServer1.invoke(invokeAssertVersion(Version.CURRENT_ORDINAL));
currentServer2.invoke(invokeAssertVersion(Version.CURRENT_ORDINAL));
// Get DistributedMembers of the servers
DistributedMember oldServerMember = oldServer.invoke(() -> getDistributedMember());
DistributedMember currentServer1Member = currentServer1.invoke(() -> getDistributedMember());
DistributedMember currentServer2Member = currentServer2.invoke(() -> getDistributedMember());
// Register function in all servers
Function function = new GetDataSerializableFunction();
invokeRunnableInVMs(invokeRegisterFunction(function), oldServer, currentServer1, currentServer2);
// Execute the function in the old server against the other servers to verify the
// DataSerializable can be serialized from a newer server to an older one.
oldServer.invoke(() -> executeFunctionAndVerify(function.getId(), "org.apache.geode.management.internal.configuration.domain.XmlEntity", currentServer1Member, currentServer2Member));
// Execute the function in a new server against the other servers to verify the
// DataSerializable can be serialized from an older server to a newer one.
currentServer1.invoke(() -> executeFunctionAndVerify(function.getId(), "org.apache.geode.management.internal.configuration.domain.XmlEntity", oldServerMember, currentServer2Member));
} finally {
invokeRunnableInVMs(true, invokeStopLocator(), oldLocator);
invokeRunnableInVMs(true, invokeCloseCache(), oldServer, currentServer1, currentServer2);
}
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class AlertAppenderJUnitTest method testListenerHandling.
/**
* Verify that adding/removing/replacing listeners works correctly.
*/
@Test
public void testListenerHandling() throws Exception {
DistributedMember member1 = createTestDistributedMember("Member1");
DistributedMember member2 = createTestDistributedMember("Member2");
DistributedMember member3 = createTestDistributedMember("Member3");
DistributedMember member4 = createTestDistributedMember("Member4");
DistributedMember member5 = createTestDistributedMember("Member5");
DistributedMember member6 = createTestDistributedMember("Member6");
LogService.setBaseLogLevel(Level.WARN);
AlertAppender.getInstance().addAlertListener(member1, Alert.SEVERE);
AlertAppender.getInstance().addAlertListener(member2, Alert.WARNING);
AlertAppender.getInstance().addAlertListener(member3, Alert.ERROR);
AlertAppender.getInstance().addAlertListener(member4, Alert.ERROR);
AlertAppender.getInstance().addAlertListener(member5, Alert.WARNING);
AlertAppender.getInstance().addAlertListener(member6, Alert.SEVERE);
Field listenersField = AlertAppender.getInstance().getClass().getDeclaredField("listeners");
listenersField.setAccessible(true);
@SuppressWarnings("unchecked") final CopyOnWriteArrayList<AlertAppender.Listener> listeners = (CopyOnWriteArrayList<AlertAppender.Listener>) listenersField.get(AlertAppender.getInstance());
// Verify add
assertSame(member5, listeners.get(0).getMember());
assertSame(member2, listeners.get(1).getMember());
assertSame(member4, listeners.get(2).getMember());
assertSame(member3, listeners.get(3).getMember());
assertSame(member6, listeners.get(4).getMember());
assertSame(member1, listeners.get(5).getMember());
assertSame(6, listeners.size());
// Verify replace with same level
AlertAppender.getInstance().addAlertListener(member5, Alert.WARNING);
assertSame(member5, listeners.get(0).getMember());
assertSame(member2, listeners.get(1).getMember());
assertSame(member4, listeners.get(2).getMember());
assertSame(member3, listeners.get(3).getMember());
assertSame(member6, listeners.get(4).getMember());
assertSame(member1, listeners.get(5).getMember());
assertSame(6, listeners.size());
// Verify replace with difference level
AlertAppender.getInstance().addAlertListener(member5, Alert.SEVERE);
assertSame(member2, listeners.get(0).getMember());
assertSame(member4, listeners.get(1).getMember());
assertSame(member3, listeners.get(2).getMember());
assertSame(member5, listeners.get(3).getMember());
assertSame(member6, listeners.get(4).getMember());
assertSame(member1, listeners.get(5).getMember());
assertSame(6, listeners.size());
// Verify remove
assertTrue(AlertAppender.getInstance().removeAlertListener(member3));
assertSame(member2, listeners.get(0).getMember());
assertSame(member4, listeners.get(1).getMember());
assertSame(member5, listeners.get(2).getMember());
assertSame(member6, listeners.get(3).getMember());
assertSame(member1, listeners.get(4).getMember());
assertSame(5, listeners.size());
assertTrue(AlertAppender.getInstance().removeAlertListener(member1));
assertTrue(AlertAppender.getInstance().removeAlertListener(member2));
assertFalse(AlertAppender.getInstance().removeAlertListener(member3));
assertTrue(AlertAppender.getInstance().removeAlertListener(member4));
assertTrue(AlertAppender.getInstance().removeAlertListener(member5));
assertTrue(AlertAppender.getInstance().removeAlertListener(member6));
}
use of org.apache.geode.distributed.DistributedMember in project geode by apache.
the class LocatorManagementDUnitTest method testPeerLocationWithPortZero.
@Test
public void testPeerLocationWithPortZero() throws Exception {
// Start the locator with port=0
int locPort = startLocator(locator, 0);
locatorMBeanExist(locator, locPort);
Host host = Host.getHost(0);
String host0 = getServerHostName(host);
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, host0 + "[" + locPort + "]");
props.setProperty(JMX_MANAGER, "true");
props.setProperty(JMX_MANAGER_START, "false");
props.setProperty(JMX_MANAGER_PORT, "0");
props.setProperty(JMX_MANAGER_HTTP_PORT, "0");
createCache(managingNode, props);
startManagingNode(managingNode);
DistributedMember locatorMember = getMember(locator);
remoteLocatorMBeanExist(managingNode, locatorMember);
}
Aggregations