Search in sources :

Example 76 with DistributedMember

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);
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FunctionContext(org.apache.geode.cache.execute.FunctionContext) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) Iterator(java.util.Iterator) DistributedMember(org.apache.geode.distributed.DistributedMember) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) FunctionAdapter(org.apache.geode.cache.execute.FunctionAdapter) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 77 with DistributedMember

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);
    }
}
Also used : SocketException(java.net.SocketException) ServerException(java.rmi.ServerException) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CacheClosedException(org.apache.geode.cache.CacheClosedException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) ServerException(java.rmi.ServerException) FunctionException(org.apache.geode.cache.execute.FunctionException) SocketException(java.net.SocketException) CacheClosedException(org.apache.geode.cache.CacheClosedException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) EOFException(java.io.EOFException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) Execution(org.apache.geode.cache.execute.Execution) SocketTimeoutException(java.net.SocketTimeoutException) Iterator(java.util.Iterator) DistributedMember(org.apache.geode.distributed.DistributedMember) EOFException(java.io.EOFException) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 78 with DistributedMember

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);
    }
}
Also used : Function(org.apache.geode.cache.execute.Function) VM(org.apache.geode.test.dunit.VM) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) Host(org.apache.geode.test.dunit.Host)

Example 79 with DistributedMember

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));
}
Also used : Field(java.lang.reflect.Field) DistributedMember(org.apache.geode.distributed.DistributedMember) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 80 with DistributedMember

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);
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) Host(org.apache.geode.test.dunit.Host) Properties(java.util.Properties) 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