Search in sources :

Example 81 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class ClientServerInvalidAndDestroyedEntryDUnitTest method getCreateServerCallable.

/* this method creates a server cache and is used by all of the tests in this class */
private SerializableCallableIF getCreateServerCallable(final String regionName, final boolean usePR) {
    return new SerializableCallable("create server and entries") {

        public Object call() {
            Cache cache = getCache();
            List<CacheServer> servers = cache.getCacheServers();
            CacheServer server;
            if (servers.size() > 0) {
                server = servers.get(0);
            } else {
                server = cache.addCacheServer();
                int port = AvailablePortHelper.getRandomAvailableTCPPort();
                server.setPort(port);
                server.setHostnameForClients("localhost");
                try {
                    server.start();
                } catch (IOException e) {
                    Assert.fail("Failed to start server ", e);
                }
            }
            if (usePR) {
                RegionFactory factory = cache.createRegionFactory(RegionShortcut.PARTITION);
                PartitionAttributesFactory pf = new PartitionAttributesFactory();
                pf.setTotalNumBuckets(2);
                factory.setPartitionAttributes(pf.create());
                factory.create(regionName);
            } else {
                cache.createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
            }
            return server.getPort();
        }
    };
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionFactory(org.apache.geode.cache.RegionFactory) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) CacheServer(org.apache.geode.cache.server.CacheServer) IOException(java.io.IOException) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache)

Example 82 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class ConcurrentMapOpsDUnitTest method createRegionsAndStartServer.

private Integer createRegionsAndStartServer(VM vm, final boolean withRedundancy) {
    return (Integer) vm.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            getCache().createRegionFactory(RegionShortcut.REPLICATE).create(REP_REG_NAME);
            if (withRedundancy) {
                getCache().createRegionFactory(RegionShortcut.PARTITION_REDUNDANT).create(PR_REG_NAME);
            } else {
                getCache().createRegionFactory(RegionShortcut.PARTITION).create(PR_REG_NAME);
            }
            int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
            CacheServer s = getCache().addCacheServer();
            s.setPort(port);
            s.start();
            return port;
        }
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) CacheServer(org.apache.geode.cache.server.CacheServer)

Example 83 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class ClientServerTransactionDUnitTest method doFailoverWork.

private void doFailoverWork(VM accessor1, VM accessor2, VM datastore, VM client, boolean serverOnDatastore, final boolean cachingProxy) {
    final int port1 = createRegionsAndStartServer(accessor1, true);
    final int port2 = accessor2 == null ? 0 : createRegionsAndStartServer(accessor2, true);
    final int port3 = serverOnDatastore ? createRegionsAndStartServer(datastore, false) : createRegionOnServer(datastore, false, false);
    /* final TXId txid = (TXId) */
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "bridge.disableShufflingOfEndpoints", "true");
            ClientCacheFactory ccf = new ClientCacheFactory();
            ccf.addPoolServer("localhost", /* getServerHostName(Host.getHost(0)) */
            port1);
            if (port2 != 0)
                ccf.addPoolServer("localhost", port2);
            if (port3 != 0)
                ccf.addPoolServer("localhost", port3);
            ccf.setPoolSubscriptionEnabled(false);
            ccf.set(LOG_LEVEL, getDUnitLogLevel());
            ClientCache cCache = getClientCache(ccf);
            ClientRegionFactory<CustId, Customer> custrf = cCache.createClientRegionFactory(cachingProxy ? ClientRegionShortcut.CACHING_PROXY : ClientRegionShortcut.PROXY);
            ClientRegionFactory<Integer, String> refrf = cCache.createClientRegionFactory(cachingProxy ? ClientRegionShortcut.CACHING_PROXY : ClientRegionShortcut.PROXY);
            Region<Integer, String> r = refrf.create(D_REFERENCE);
            Region<CustId, Customer> pr = custrf.create(CUSTOMER);
            // Region<Integer, String> order = refrf.create(ORDER);
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            mgr.begin();
            for (int i = 0; i < 5; i++) {
                CustId custId = new CustId(i);
                Customer cust = new Customer("name" + i, "address" + i);
                getGemfireCache().getLogger().info("SWAP:putting:" + custId);
                pr.put(custId, cust);
                r.put(i, "value" + i);
            }
            return mgr.getTransactionId();
        }
    });
    accessor1.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            for (CacheServer s : getCache().getCacheServers()) {
                getCache().getLogger().info("SWAP:Stopping " + s);
                s.stop();
            }
            return null;
        }
    });
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            /* TXManagerImpl mgr = */
            getGemfireCache().getTxManager();
            Region<Integer, String> r = getGemfireCache().getRegion(D_REFERENCE);
            Region<CustId, Customer> pr = getGemfireCache().getRegion(CUSTOMER);
            for (int i = 5; i < 10; i++) {
                CustId custId = new CustId(i);
                Customer cust = new Customer("name" + i, "address" + i);
                getGemfireCache().getLogger().info("SWAP:AfterFailover:putting:" + custId);
                pr.put(custId, cust);
                r.put(i, "value" + i);
            }
            return null;
        }
    });
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            assertEquals(1, mgr.hostedTransactionsInProgressForTest());
            return null;
        }
    });
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            TXManagerImpl mgr = getGemfireCache().getTxManager();
            Region<Integer, String> r = getGemfireCache().getRegion(D_REFERENCE);
            Region<CustId, Customer> pr = getGemfireCache().getRegion(CUSTOMER);
            mgr.commit();
            for (int i = 0; i < 10; i++) {
                if (cachingProxy) {
                    assertTrue(pr.containsKey(new CustId(i)));
                    assertTrue(r.containsKey(i));
                }
                assertEquals(new Customer("name" + i, "address" + i), pr.get(new CustId(i)));
                assertEquals("value" + i, r.get(i));
            }
            return null;
        }
    });
}
Also used : CustId(org.apache.geode.internal.cache.execute.data.CustId) Customer(org.apache.geode.internal.cache.execute.data.Customer) CacheServer(org.apache.geode.cache.server.CacheServer) RollbackException(javax.transaction.RollbackException)

Example 84 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class ClientServerTransactionDUnitTest method getVMForTransactions.

/*
   * (non-Javadoc)
   * 
   * @see org.apache.geode.internal.cache.RemoteTransactionDUnitTest#getVMForTransactions(dunit.VM,
   * dunit.VM)
   */
@Override
public VM getVMForTransactions(VM accessor, VM datastore) {
    // create a cache server in the accessor VM and then create and return
    // a client VM
    final int serverPort = (Integer) accessor.invoke(new SerializableCallable("create cache server") {

        public Object call() throws Exception {
            TXManagerImpl txMgr = (TXManagerImpl) getCache().getCacheTransactionManager();
            txMgr.setTransactionTimeToLiveForTest(10);
            int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
            CacheServer s = getCache().addCacheServer();
            s.setPort(port);
            s.start();
            return port;
        }
    });
    // superclass always uses 0 and 1
    VM clientVM = Host.getHost(0).getVM(2);
    createClientRegion(clientVM, serverPort, false, false);
    return clientVM;
}
Also used : CacheServer(org.apache.geode.cache.server.CacheServer)

Example 85 with CacheServer

use of org.apache.geode.cache.server.CacheServer in project geode by apache.

the class DeltaPropagationDUnitTest method createServerCache.

public static Integer createServerCache(String ePolicy, Integer cap, Integer listenerCode, Boolean conflate, Compressor compressor) throws Exception {
    ConnectionTable.threadWantsSharedResources();
    new DeltaPropagationDUnitTest().createCache(new Properties());
    AttributesFactory factory = new AttributesFactory();
    factory.setEnableSubscriptionConflation(conflate);
    if (listenerCode.intValue() != 0) {
        factory.addCacheListener(getCacheListener(listenerCode));
    }
    if (compressor != null) {
        factory.setCompressor(compressor);
    }
    if (listenerCode.intValue() == C2S2S_SERVER_LISTENER) {
        factory.setScope(Scope.DISTRIBUTED_NO_ACK);
        factory.setDataPolicy(DataPolicy.NORMAL);
        factory.setConcurrencyChecksEnabled(false);
        RegionAttributes attrs = factory.create();
        Region r = cache.createRegion(regionName, attrs);
        logger = cache.getLogger();
        r.create(DELTA_KEY, deltaPut[0]);
    } else {
        factory.setScope(Scope.DISTRIBUTED_ACK);
        factory.setDataPolicy(DataPolicy.REPLICATE);
        factory.setConcurrencyChecksEnabled(false);
        RegionAttributes attrs = factory.create();
        cache.createRegion(regionName, attrs);
        logger = cache.getLogger();
    }
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    CacheServer server1 = cache.addCacheServer();
    server1.setPort(port);
    server1.setNotifyBySubscription(true);
    if (ePolicy != null) {
        File overflowDirectory = new File("bsi_overflow_" + port);
        overflowDirectory.mkdir();
        DiskStoreFactory dsf = cache.createDiskStoreFactory();
        File[] dirs1 = new File[] { overflowDirectory };
        server1.getClientSubscriptionConfig().setEvictionPolicy(ePolicy);
        server1.getClientSubscriptionConfig().setCapacity(cap.intValue());
        // specify diskstore for this server
        server1.getClientSubscriptionConfig().setDiskStoreName(dsf.setDiskDirs(dirs1).create("bsi").getName());
    }
    server1.start();
    return new Integer(server1.getPort());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Region(org.apache.geode.cache.Region) CacheServer(org.apache.geode.cache.server.CacheServer) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory)

Aggregations

CacheServer (org.apache.geode.cache.server.CacheServer)323 AttributesFactory (org.apache.geode.cache.AttributesFactory)99 Properties (java.util.Properties)97 Test (org.junit.Test)77 Cache (org.apache.geode.cache.Cache)76 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)76 RegionAttributes (org.apache.geode.cache.RegionAttributes)60 IOException (java.io.IOException)53 ClientCache (org.apache.geode.cache.client.ClientCache)53 Region (org.apache.geode.cache.Region)50 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)49 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)33 Iterator (java.util.Iterator)31 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)31 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)30 Host (org.apache.geode.test.dunit.Host)27 VM (org.apache.geode.test.dunit.VM)25 DistributedSystem (org.apache.geode.distributed.DistributedSystem)20 CacheException (org.apache.geode.cache.CacheException)17 CacheFactory (org.apache.geode.cache.CacheFactory)17