Search in sources :

Example 1 with CacheFactory

use of org.apache.geode.cache.CacheFactory in project geode by apache.

the class RestInterfaceJUnitTest method setupGemFire.

@Before
public void setupGemFire() {
    AgentUtil agentUtil = new AgentUtil(GemFireVersion.getGemFireVersion());
    if (agentUtil.findWarLocation("geode-web-api") == null) {
        fail("unable to locate geode-web-api WAR file");
    }
    if (gemfireCache == null) {
        gemfireProperties = (gemfireProperties != null ? gemfireProperties : new Properties());
        gemfireCache = new CacheFactory().setPdxSerializer(new ReflectionBasedAutoSerializer(Person.class.getName().replaceAll("\\$", "."))).setPdxReadSerialized(true).setPdxIgnoreUnreadFields(false).set("name", getClass().getSimpleName()).set(MCAST_PORT, "0").set(LOG_LEVEL, "config").set(HTTP_SERVICE_BIND_ADDRESS, "localhost").set(HTTP_SERVICE_PORT, String.valueOf(getHttpServicePort())).set(START_DEV_REST_API, "true").create();
        RegionFactory<String, Object> peopleRegionFactory = gemfireCache.createRegionFactory();
        peopleRegionFactory.setDataPolicy(DataPolicy.PARTITION);
        peopleRegionFactory.setKeyConstraint(String.class);
        peopleRegionFactory.setValueConstraint(Object.class);
        people = peopleRegionFactory.create("People");
    }
}
Also used : ReflectionBasedAutoSerializer(org.apache.geode.pdx.ReflectionBasedAutoSerializer) AgentUtil(org.apache.geode.management.internal.AgentUtil) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory) Before(org.junit.Before)

Example 2 with CacheFactory

use of org.apache.geode.cache.CacheFactory in project geode by apache.

the class InternalLocator method startCache.

private void startCache(DistributedSystem ds) {
    InternalCache internalCache = GemFireCacheImpl.getInstance();
    if (internalCache == null) {
        logger.info("Creating cache for locator.");
        this.myCache = (InternalCache) new CacheFactory(ds.getProperties()).create();
        internalCache = this.myCache;
    } else {
        logger.info("Using existing cache for locator.");
        ((InternalDistributedSystem) ds).handleResourceEvent(ResourceEvent.LOCATOR_START, this);
    }
    startJmxManagerLocationService(internalCache);
    startSharedConfigurationService(internalCache);
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) CacheFactory(org.apache.geode.cache.CacheFactory)

Example 3 with CacheFactory

use of org.apache.geode.cache.CacheFactory in project geode by apache.

the class ClientServerRegisterInterestsDUnitTest method setupGemFireCacheServer.

private void setupGemFireCacheServer() {
    Host localhost = Host.getHost(0);
    gemfireServerVm = localhost.getVM(0);
    serverPort.set(AvailablePortHelper.getRandomAvailableTCPPort());
    gemfireServerVm.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            try {
                Cache cache = new CacheFactory().set("name", "ClientServerRegisterInterestsTestGemFireServer").set(MCAST_PORT, "0").set(LOG_FILE, "clientServerRegisterInterestsTest.log").set(LOG_LEVEL, "config").create();
                RegionFactory<String, String> regionFactory = cache.createRegionFactory();
                regionFactory.setDataPolicy(DataPolicy.REPLICATE);
                regionFactory.setKeyConstraint(String.class);
                regionFactory.setValueConstraint(String.class);
                Region<String, String> example = regionFactory.create("Example");
                assertNotNull("The 'Example' Region was not properly configured and initialized!", example);
                assertEquals("/Example", example.getFullPath());
                assertEquals("Example", example.getName());
                assertTrue(example.isEmpty());
                example.put("1", "ONE");
                assertFalse(example.isEmpty());
                assertEquals(1, example.size());
                CacheServer cacheServer = cache.addCacheServer();
                cacheServer.setPort(serverPort.get());
                cacheServer.setMaxConnections(10);
                ClientSubscriptionConfig clientSubscriptionConfig = cacheServer.getClientSubscriptionConfig();
                clientSubscriptionConfig.setCapacity(100);
                clientSubscriptionConfig.setEvictionPolicy("entry");
                cacheServer.start();
                assertTrue("Cache Server is not running!", cacheServer.isRunning());
            } catch (UnknownHostException ignore) {
                throw new RuntimeException(ignore);
            } catch (IOException e) {
                throw new RuntimeException(String.format("Failed to start the GemFire Cache Server listening on port (%1$d) due to IO error!", serverPort.get()), e);
            }
        }
    });
}
Also used : UnknownHostException(java.net.UnknownHostException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) RegionFactory(org.apache.geode.cache.RegionFactory) ClientSubscriptionConfig(org.apache.geode.cache.server.ClientSubscriptionConfig) Region(org.apache.geode.cache.Region) CacheServer(org.apache.geode.cache.server.CacheServer) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache)

Example 4 with CacheFactory

use of org.apache.geode.cache.CacheFactory in project geode by apache.

the class RemoveAllCacheListenerClientServerRegressionTest method setupGemFireCacheServer.

// ================================================================================
private void setupGemFireCacheServer(RegionShortcut shortcut, boolean concChecks) {
    serverVM = Host.getHost(0).getVM(0);
    serverPort.set(AvailablePortHelper.getRandomAvailableTCPPort());
    String serverName = this.getClass().getSimpleName() + "_server";
    serverVM.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            try {
                Cache cache = new CacheFactory().set("name", serverName).set(MCAST_PORT, "0").set(LOG_FILE, serverName + ".log").set(LOG_LEVEL, "config").set("locators", "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]").create();
                RegionFactory<String, String> regionFactory = cache.createRegionFactory(shortcut);
                regionFactory.addCacheListener(new TestListener());
                regionFactory.setConcurrencyChecksEnabled(concChecks);
                regionFactory.create(REGION_NAME);
                CacheServer cacheServer = cache.addCacheServer();
                cacheServer.setPort(serverPort.get());
                cacheServer.setMaxConnections(10);
                cacheServer.start();
                assertTrue("Cache Server is not running!", cacheServer.isRunning());
            } catch (UnknownHostException ignore) {
                throw new RuntimeException(ignore);
            } catch (IOException e) {
                throw new RuntimeException("Failed to start cache server " + serverName + " on port " + serverPort.get() + ": " + e.getStackTrace());
            }
        }
    });
}
Also used : RegionFactory(org.apache.geode.cache.RegionFactory) UnknownHostException(java.net.UnknownHostException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheServer(org.apache.geode.cache.server.CacheServer) IOException(java.io.IOException) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache)

Example 5 with CacheFactory

use of org.apache.geode.cache.CacheFactory in project geode by apache.

the class ParallelSnapshotDUnitTest method loadCache.

public void loadCache() throws Exception {
    SerializableCallable setup = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer());
            Cache cache = getCache(cf);
            RegionGenerator rgen = new RegionGenerator();
            rgen.createRegion(cache, null, RegionType.PARTITION, "test");
            return null;
        }
    };
    forEachVm(setup, true);
}
Also used : MyPdxSerializer(com.examples.snapshot.MyPdxSerializer) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) CacheFactory(org.apache.geode.cache.CacheFactory) Cache(org.apache.geode.cache.Cache)

Aggregations

CacheFactory (org.apache.geode.cache.CacheFactory)125 Properties (java.util.Properties)51 Test (org.junit.Test)51 Cache (org.apache.geode.cache.Cache)44 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)38 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)28 Region (org.apache.geode.cache.Region)21 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)18 CacheServer (org.apache.geode.cache.server.CacheServer)17 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)17 File (java.io.File)15 Before (org.junit.Before)14 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)13 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)12 ClientCache (org.apache.geode.cache.client.ClientCache)11 Host (org.apache.geode.test.dunit.Host)11 IOException (java.io.IOException)10 AttributesFactory (org.apache.geode.cache.AttributesFactory)10 PdxType (org.apache.geode.pdx.internal.PdxType)9 MyPdxSerializer (com.examples.snapshot.MyPdxSerializer)8