Search in sources :

Example 16 with DistributedSystem

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

the class TestFunction method executeFunctionReturningArgs.

public void executeFunctionReturningArgs(FunctionContext context) {
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    logger.info("Executing executeFunctionReturningArgs in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
    if (!hasResult()) {
        return;
    }
    Object[] args = (Object[]) context.getArguments();
    if (args != null) {
        context.getResultSender().lastResult(args[0]);
    } else {
        context.getResultSender().lastResult(Boolean.FALSE);
    }
}
Also used : LogWriter(org.apache.geode.LogWriter) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 17 with DistributedSystem

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

the class TestFunction method execute1.

public void execute1(FunctionContext context) {
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    logger.info("Executing execute1 in TestFunction on Member : " + ds.getDistributedMember() + "with Context : " + context);
    if (!hasResult()) {
        return;
    }
    if (context.getArguments() instanceof Boolean) {
        // context.getResultSender().sendResult();
        context.getResultSender().lastResult((Serializable) context.getArguments());
    } else if (context.getArguments() instanceof String) {
        /*
       * String key = (String)context.getArguments(); return key;
       */
        context.getResultSender().lastResult((Serializable) context.getArguments());
    } else if (context.getArguments() instanceof Set) {
        Set origKeys = (Set) context.getArguments();
        ArrayList vals = new ArrayList();
        for (Iterator i = origKeys.iterator(); i.hasNext(); ) {
            Object val = i.next();
            if (val != null) {
                vals.add(val);
            }
        }
        /* return vals; */
        context.getResultSender().lastResult(vals);
    } else {
        /* return Boolean.FALSE; */
        context.getResultSender().lastResult(Boolean.FALSE);
    }
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) LogWriter(org.apache.geode.LogWriter) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 18 with DistributedSystem

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

the class TestFunction method execute2.

public void execute2(FunctionContext context) {
    if (context instanceof RegionFunctionContext) {
        RegionFunctionContext rfContext = (RegionFunctionContext) context;
        rfContext.getDataSet().getCache().getLogger().info("Executing function :  TestFunction2.execute " + rfContext);
        if (rfContext.getArguments() instanceof Boolean) {
            /* return rfContext.getArguments(); */
            if (hasResult()) {
                rfContext.getResultSender().lastResult((Serializable) rfContext.getArguments());
            } else {
                rfContext.getDataSet().getCache().getLogger().info("Executing function :  TestFunction2.execute " + rfContext);
                while (true && !rfContext.getDataSet().isDestroyed()) {
                    rfContext.getDataSet().getCache().getLogger().info("For Bug43513 ");
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException ie) {
                        Thread.currentThread().interrupt();
                        return;
                    }
                }
            }
        } else if (rfContext.getArguments() instanceof String) {
            String key = (String) rfContext.getArguments();
            if (key.equals("TestingTimeOut")) {
                // PRFunctionExecutionDUnitTest#testRemoteMultiKeyExecution_timeout
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    rfContext.getDataSet().getCache().getLogger().warning("Got Exception : Thread Interrupted" + e);
                }
            }
            if (PartitionRegionHelper.isPartitionedRegion(rfContext.getDataSet())) {
                /*
           * return (Serializable)PartitionRegionHelper.getLocalDataForContext(rfContext).get(key);
           */
                rfContext.getResultSender().lastResult((Serializable) PartitionRegionHelper.getLocalDataForContext(rfContext).get(key));
            } else {
                rfContext.getResultSender().lastResult((Serializable) rfContext.getDataSet().get(key));
            }
        /* return (Serializable)rfContext.getDataSet().get(key); */
        } else if (rfContext.getArguments() instanceof Set) {
            Set origKeys = (Set) rfContext.getArguments();
            ArrayList vals = new ArrayList();
            for (Object key : origKeys) {
                Object val = PartitionRegionHelper.getLocalDataForContext(rfContext).get(key);
                if (val != null) {
                    vals.add(val);
                }
            }
            rfContext.getResultSender().lastResult(vals);
        /* return vals; */
        } else if (rfContext.getArguments() instanceof HashMap) {
            HashMap putData = (HashMap) rfContext.getArguments();
            for (Iterator i = putData.entrySet().iterator(); i.hasNext(); ) {
                Map.Entry me = (Map.Entry) i.next();
                rfContext.getDataSet().put(me.getKey(), me.getValue());
            }
            rfContext.getResultSender().lastResult(Boolean.TRUE);
        } else {
            rfContext.getResultSender().lastResult(Boolean.FALSE);
        }
    } else {
        if (hasResult()) {
            context.getResultSender().lastResult(Boolean.FALSE);
        } else {
            DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
            LogWriter logger = ds.getLogWriter();
            logger.info("Executing in TestFunction on Server : " + ds.getDistributedMember() + "with Context : " + context);
            while (ds.isConnected()) {
                logger.fine("Just executing function in infinite loop for Bug43513");
                try {
                    Thread.sleep(250);
                } catch (InterruptedException e) {
                    return;
                }
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) LogWriter(org.apache.geode.LogWriter) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 19 with DistributedSystem

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

the class TestFunction method executeHAAndNonHAOnRegion.

public void executeHAAndNonHAOnRegion(FunctionContext context) {
    List<CacheServer> servers = CacheFactory.getAnyInstance().getCacheServers();
    ArrayList<String> args = (ArrayList<String>) context.getArguments();
    RegionFunctionContext rfContext = (RegionFunctionContext) context;
    rfContext.getDataSet().getCache().getLogger().info("Executing function :  executeHAAndNonHAOnRegion " + rfContext);
    Region r = CacheFactory.getAnyInstance().getRegion(args.get(0));
    String testName = args.get(1);
    Integer numTimesStopped = (Integer) r.get("stopped");
    Integer numTimesSentResult = (Integer) r.get("sentresult");
    if (context.isPossibleDuplicate()) {
        if (testName.equals("regionExecutionHATwoServerDown")) {
            if ((Integer) r.get("stopped") == 2) {
                if (numTimesSentResult == null) {
                    r.put("sentresult", 1);
                } else {
                    r.put("sentresult", ++numTimesSentResult);
                }
                context.getResultSender().lastResult(args.get(0));
            } else {
                r.put("stopped", ++numTimesStopped);
                for (CacheServer s : servers) {
                    if (((CacheServerImpl) s).getSystem().getDistributedMember().equals(((GemFireCacheImpl) CacheFactory.getAnyInstance()).getMyId())) {
                        s.stop();
                        DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
                        ds.disconnect();
                    }
                }
            }
        } else if (testName.equals("regionExecutionHAOneServerDown")) {
            if (numTimesSentResult == null) {
                r.put("sentresult", 1);
            } else {
                r.put("sentresult", ++numTimesSentResult);
            }
            context.getResultSender().lastResult(args.get(0));
        } else {
            context.getResultSender().lastResult(args.get(0));
        }
    } else {
        if (numTimesStopped == null) {
            r.put("stopped", 1);
        } else {
            r.put("stopped", ++numTimesStopped);
        }
        for (CacheServer s : servers) {
            if (((CacheServerImpl) s).getSystem().getDistributedMember().equals(((GemFireCacheImpl) CacheFactory.getAnyInstance()).getMyId())) {
                s.stop();
                DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
                ds.disconnect();
            }
        }
        context.getResultSender().lastResult(args.get(0));
    }
}
Also used : ArrayList(java.util.ArrayList) CacheServer(org.apache.geode.cache.server.CacheServer) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 20 with DistributedSystem

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

the class TestFunction method executeFunctionRunningForLongTime.

public void executeFunctionRunningForLongTime(FunctionContext context) {
    DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
    LogWriter logger = ds.getLogWriter();
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {
        logger.info("Exception in executeFunctionRunningForLongTime");
    }
    context.getResultSender().lastResult("Ran executeFunctionRunningForLongTime for 10000000");
}
Also used : LogWriter(org.apache.geode.LogWriter) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Aggregations

DistributedSystem (org.apache.geode.distributed.DistributedSystem)250 Properties (java.util.Properties)102 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)65 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)61 Test (org.junit.Test)59 Cache (org.apache.geode.cache.Cache)55 AttributesFactory (org.apache.geode.cache.AttributesFactory)34 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)30 Region (org.apache.geode.cache.Region)24 IOException (java.io.IOException)20 CacheServer (org.apache.geode.cache.server.CacheServer)20 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)20 InternalCache (org.apache.geode.internal.cache.InternalCache)16 IgnoredException (org.apache.geode.test.dunit.IgnoredException)16 ArrayList (java.util.ArrayList)15 LogWriter (org.apache.geode.LogWriter)15 DistributedMember (org.apache.geode.distributed.DistributedMember)15 LocalRegion (org.apache.geode.internal.cache.LocalRegion)15 RegionAttributes (org.apache.geode.cache.RegionAttributes)14 Pool (org.apache.geode.cache.client.Pool)14