Search in sources :

Example 46 with ClientCacheFactory

use of org.apache.geode.cache.client.ClientCacheFactory in project geode by apache.

the class OnGroupsFunctionExecutionDUnitTest method testNoAckGroupsFunction.

@Test
public void testNoAckGroupsFunction() {
    // Workaround for #52005. This is a product bug
    // that should be fixed
    IgnoredException.addIgnoredException("Cannot return any result");
    Host host = Host.getHost(0);
    final VM server0 = host.getVM(0);
    final VM server1 = host.getVM(1);
    final VM server2 = host.getVM(2);
    VM client = host.getVM(3);
    VM locator = Host.getLocator();
    final String regionName = getName();
    initVM(server0, "mg,g0", regionName, true);
    initVM(server1, "g1", regionName, true);
    initVM(server2, "g0,g1", regionName, true);
    final int locatorPort = getLocatorPort(locator);
    final String hostName = host.getHostName();
    client.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            try {
                Cache c = CacheFactory.getAnyInstance();
                c.close();
            } catch (CacheClosedException cce) {
            }
            disconnectFromDS();
            LogWriterUtils.getLogWriter().fine("SWAP:creating client cache");
            ClientCacheFactory ccf = new ClientCacheFactory();
            ccf.addPoolLocator(hostName, locatorPort);
            ccf.setPoolServerGroup("mg");
            ccf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            ClientCache c = ccf.create();
            c.getLogger().info("SWAP:invoking function from client on g0");
            Execution e = InternalFunctionService.onServers(c, "g0");
            e.execute(new OnGroupsNoAckFunction());
            return null;
        }
    });
    WaitCriterion wc = new WaitCriterion() {

        @Override
        public boolean done() {
            int c0 = getInvocationCount(server0);
            int c1 = getInvocationCount(server1);
            int c2 = getInvocationCount(server2);
            return (c0 + c1 + c2) == 2;
        }

        @Override
        public String description() {
            return "OnGroupsNoAck invocation count mismatch";
        }
    };
    Wait.waitForCriterion(wc, 30000, 1000, true);
    resetInvocationCount(server0);
    resetInvocationCount(server1);
    resetInvocationCount(server2);
    client.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            ClientCache c = ClientCacheFactory.getAnyInstance();
            Execution e = InternalFunctionService.onServer(c, "g1");
            e.execute(new OnGroupsNoAckFunction());
            return null;
        }
    });
    // pause here to verify that we do not get more than 1 invocation
    Wait.pause(5000);
    WaitCriterion wc2 = new WaitCriterion() {

        @Override
        public boolean done() {
            int c0 = getInvocationCount(server0);
            int c1 = getInvocationCount(server1);
            int c2 = getInvocationCount(server2);
            return (c0 + c1 + c2) == 1;
        }

        @Override
        public String description() {
            return "OnGroupsNoAck invocation count mismatch";
        }
    };
    Wait.waitForCriterion(wc2, 30000, 1000, true);
    resetInvocationCount(server0);
    resetInvocationCount(server1);
    resetInvocationCount(server2);
}
Also used : Host(org.apache.geode.test.dunit.Host) CacheClosedException(org.apache.geode.cache.CacheClosedException) ClientCache(org.apache.geode.cache.client.ClientCache) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Execution(org.apache.geode.cache.execute.Execution) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 47 with ClientCacheFactory

use of org.apache.geode.cache.client.ClientCacheFactory in project geode by apache.

the class OnGroupsFunctionExecutionDUnitTest method testClientServerIgnoreMemberFailure.

@Test
public void testClientServerIgnoreMemberFailure() {
    Host host = Host.getHost(0);
    VM server0 = host.getVM(0);
    VM server1 = host.getVM(1);
    VM server2 = host.getVM(2);
    VM client = host.getVM(3);
    VM locator = Host.getLocator();
    final String regionName = getName();
    initVM(server0, "mg,g0", regionName, true);
    initVM(server1, "g1", regionName, true);
    initVM(server2, "g0,g1,g2", regionName, true);
    final int locatorPort = getLocatorPort(locator);
    final String hostName = host.getHostName();
    client.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            try {
                Cache c = CacheFactory.getAnyInstance();
                c.close();
            } catch (CacheClosedException cce) {
            }
            disconnectFromDS();
            LogWriterUtils.getLogWriter().fine("SWAP:creating client cache");
            ClientCacheFactory ccf = new ClientCacheFactory();
            ccf.addPoolLocator(hostName, locatorPort);
            ccf.setPoolServerGroup("mg");
            ccf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            ClientCache c = ccf.create();
            Execution e = InternalFunctionService.onServers(c, "g1");
            ArrayList<String> args = new ArrayList<String>();
            args.add("disconnect");
            args.add("g2");
            e = e.setArguments(args);
            ((AbstractExecution) e).setIgnoreDepartedMembers(true);
            ArrayList l = (ArrayList) e.execute(new OnGroupsExceptionFunction()).getResult();
            LogWriterUtils.getLogWriter().info("SWAP:result:" + l);
            assertEquals(2, l.size());
            if (l.get(0) instanceof Throwable) {
                assertTrue((Boolean) l.get(1));
            } else if (l.get(0) instanceof Boolean) {
                assertTrue(l.get(1) instanceof Throwable);
            } else {
                fail("expected to find a Boolean or throwable at index 0");
            }
            return null;
        }
    });
}
Also used : ArrayList(java.util.ArrayList) Host(org.apache.geode.test.dunit.Host) CacheClosedException(org.apache.geode.cache.CacheClosedException) ClientCache(org.apache.geode.cache.client.ClientCache) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Execution(org.apache.geode.cache.execute.Execution) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 48 with ClientCacheFactory

use of org.apache.geode.cache.client.ClientCacheFactory in project geode by apache.

the class OnGroupsFunctionExecutionDUnitTest method testClientServerException.

@Test
public void testClientServerException() {
    Host host = Host.getHost(0);
    VM server0 = host.getVM(0);
    VM server1 = host.getVM(1);
    VM server2 = host.getVM(2);
    VM client = host.getVM(3);
    VM locator = Host.getLocator();
    final String regionName = getName();
    initVM(server0, "mg,g0", regionName, true);
    initVM(server1, "g1", regionName, true);
    initVM(server2, "g0,g1,g2", regionName, true);
    final int locatorPort = getLocatorPort(locator);
    final String hostName = host.getHostName();
    client.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            try {
                Cache c = CacheFactory.getAnyInstance();
                c.close();
            } catch (CacheClosedException cce) {
            }
            disconnectFromDS();
            LogWriterUtils.getLogWriter().fine("SWAP:creating client cache");
            ClientCacheFactory ccf = new ClientCacheFactory();
            ccf.addPoolLocator(hostName, locatorPort);
            ccf.setPoolServerGroup("mg");
            ccf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            ClientCache c = ccf.create();
            IgnoredException expected = IgnoredException.addIgnoredException("No member found");
            try {
                InternalFunctionService.onServers(c, "no such group").execute(new OnGroupsFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException e) {
            } finally {
                expected.remove();
            }
            IgnoredException.addIgnoredException("NullPointerException");
            Execution e = InternalFunctionService.onServers(c, "mg");
            ArrayList<String> args = new ArrayList<String>();
            args.add("runtime");
            e = e.setArguments(args);
            try {
                e.execute(new OnGroupsExceptionFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException ex) {
                assertTrue(ex.getCause() instanceof NullPointerException);
            }
            Execution e1 = InternalFunctionService.onServers(c, "g1");
            e1 = e1.setArguments(args);
            try {
                e1.execute(new OnGroupsExceptionFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException ex) {
                assertTrue(ex.getCause() instanceof NullPointerException);
            }
            // only one member
            Execution e2 = InternalFunctionService.onServers(c, "g1");
            args.add("g2");
            e2 = e2.setArguments(args);
            try {
                e2.execute(new OnGroupsExceptionFunction()).getResult();
                fail("expected exception not thrown");
            } catch (FunctionException ex) {
                assertTrue(ex.getCause() instanceof NullPointerException);
            }
            return null;
        }
    });
}
Also used : FunctionException(org.apache.geode.cache.execute.FunctionException) ArrayList(java.util.ArrayList) Host(org.apache.geode.test.dunit.Host) CacheClosedException(org.apache.geode.cache.CacheClosedException) ClientCache(org.apache.geode.cache.client.ClientCache) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Execution(org.apache.geode.cache.execute.Execution) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 49 with ClientCacheFactory

use of org.apache.geode.cache.client.ClientCacheFactory in project geode by apache.

the class MainWithChildrenRollingFileHandlerDUnitTest method testGeode2874_nameWithoutExtensionDoesNotThrowOnMemberRestart.

@Test
public void testGeode2874_nameWithoutExtensionDoesNotThrowOnMemberRestart() throws Exception {
    MemberVM<Locator> locatorVM = locatorServerStartupRule.startLocatorVM(0);
    ClientCacheFactory clientCacheFactory = new ClientCacheFactory();
    clientCacheFactory.addPoolLocator(InetAddress.getLocalHost().toString(), locatorVM.getPort());
    clientCacheFactory.set(LOG_FILE, "nameWithoutExtension");
    ClientCache clientCache = clientCacheFactory.create();
    clientCache.close();
    ClientCache clientCache2 = clientCacheFactory.create();
}
Also used : Locator(org.apache.geode.test.dunit.rules.Locator) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 50 with ClientCacheFactory

use of org.apache.geode.cache.client.ClientCacheFactory in project geode by apache.

the class LuceneClientSecurityDUnitTest method startClient.

private void startClient(String userName, int serverPort) {
    Properties props = new Properties();
    props.setProperty("security-username", userName);
    props.setProperty("security-password", userName);
    props.setProperty(SECURITY_CLIENT_AUTH_INIT, UserPasswordAuthInit.class.getName());
    ClientCacheFactory clientCacheFactory = new ClientCacheFactory(props);
    clientCacheFactory.addPoolServer("localhost", serverPort);
    ClientCache clientCache = getClientCache(clientCacheFactory);
    clientCache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(REGION_NAME);
}
Also used : ClientCache(org.apache.geode.cache.client.ClientCache) Properties(java.util.Properties) UserPasswordAuthInit(org.apache.geode.security.templates.UserPasswordAuthInit) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Aggregations

ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)87 ClientCache (org.apache.geode.cache.client.ClientCache)65 Test (org.junit.Test)45 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)44 VM (org.apache.geode.test.dunit.VM)42 Host (org.apache.geode.test.dunit.Host)40 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)40 Region (org.apache.geode.cache.Region)37 Properties (java.util.Properties)23 QueryService (org.apache.geode.cache.query.QueryService)22 SelectResults (org.apache.geode.cache.query.SelectResults)22 CacheServer (org.apache.geode.cache.server.CacheServer)22 Cache (org.apache.geode.cache.Cache)19 CacheException (org.apache.geode.cache.CacheException)14 PortfolioPdx (org.apache.geode.cache.query.data.PortfolioPdx)13 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)13 IOException (java.io.IOException)12 IgnoredException (org.apache.geode.test.dunit.IgnoredException)12 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)11 PdxInstance (org.apache.geode.pdx.PdxInstance)10