Search in sources :

Example 6 with CacheFactory

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

the class SnapshotByteArrayDUnitTest method loadCache.

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

        @Override
        public Object call() throws Exception {
            CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer()).setPdxPersistent(true);
            Cache cache = getCache(cf);
            RegionGenerator rgen = new RegionGenerator();
            rgen.createRegion(cache, null, RegionType.REPLICATE, "snapshot-ops");
            return null;
        }
    };
    SnapshotDUnitTest.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)

Example 7 with CacheFactory

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

the class QueryParamsAuthorizationDUnitTest method testQueryParamsInAuthCallback.

@Ignore("Bug 51079")
@Test
public void testQueryParamsInAuthCallback() throws Exception {
    final Host host = Host.getHost(0);
    final VM server1 = host.getVM(0);
    final VM client = host.getVM(1);
    // create servers and regions
    final int port = (Integer) server1.invoke(new SerializableCallable("Create Server1") {

        @Override
        public Object call() throws Exception {
            CacheFactory cf = new CacheFactory().set(MCAST_PORT, "0").set(SECURITY_CLIENT_ACCESSOR, "org.apache.geode.cache.query.dunit.QueryAuthorization.create").set(SECURITY_CLIENT_AUTHENTICATOR, DummyAuthenticator.class.getName() + ".create");
            Cache cache = getCache(cf);
            cache.createRegionFactory(RegionShortcut.REPLICATE).create(regName);
            CacheServer server = cache.addCacheServer();
            int port = AvailablePortHelper.getRandomAvailablePortForDUnitSite();
            server.setPort(port);
            server.start();
            return port;
        }
    });
    // create client
    client.invoke(new SerializableCallable("Create client") {

        @Override
        public Object call() throws Exception {
            ClientCacheFactory ccf = new ClientCacheFactory().addPoolServer(NetworkUtils.getServerHostName(server1.getHost()), port).set(SECURITY_CLIENT_AUTH_INIT, UserPasswordAuthInit.class.getName() + ".create").set(SECURITY_PREFIX + "username", "root").set(SECURITY_PREFIX + "password", "root");
            ClientCache cache = getClientCache(ccf);
            Region r1 = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regName);
            for (int i = 0; i < 20; i++) {
                r1.put("key-" + i, new Portfolio(i));
            }
            QueryService qs = cache.getQueryService();
            Object[] params = new Object[] { "active", 0 };
            SelectResults sr = (SelectResults) qs.newQuery("select * from " + r1.getFullPath() + " where status = $1 and ID > $2 ").execute(params);
            assertTrue("Result size should be greater than 0 ", sr.size() > 0);
            return null;
        }
    });
}
Also used : Portfolio(org.apache.geode.cache.query.data.Portfolio) Host(org.apache.geode.test.dunit.Host) ClientCache(org.apache.geode.cache.client.ClientCache) UserPasswordAuthInit(org.apache.geode.security.templates.UserPasswordAuthInit) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) SelectResults(org.apache.geode.cache.query.SelectResults) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) CacheServer(org.apache.geode.cache.server.CacheServer) Region(org.apache.geode.cache.Region) CacheFactory(org.apache.geode.cache.CacheFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Ignore(org.junit.Ignore) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 8 with CacheFactory

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

the class SnapshotPerformanceDUnitTest method createCache.

private void createCache() throws Exception {
    SerializableCallable setup = new SerializableCallable() {

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

Example 9 with CacheFactory

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

the class SnapshotTestCase method setUp.

@Before
public void setUp() throws Exception {
    store = new File("store-" + Math.abs(new Random().nextInt()));
    store.mkdir();
    snaps = new File("snapshots-" + Math.abs(new Random().nextInt()));
    snaps.mkdir();
    rgen = new RegionGenerator();
    CacheFactory cf = new CacheFactory().set(MCAST_PORT, "0").set(LOG_LEVEL, "error");
    cache = cf.create();
    ds = cache.createDiskStoreFactory().setMaxOplogSize(1).setDiskDirs(new File[] { store }).create("snapshotTest");
}
Also used : Random(java.util.Random) CacheFactory(org.apache.geode.cache.CacheFactory) File(java.io.File) Before(org.junit.Before)

Example 10 with CacheFactory

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

the class WANBootStrapping_Site1_Add method main.

public static void main(String[] args) {
    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "DistributedSystemListener", "com.main.MyDistributedSystemListener");
    // Create a locator and a cache
    System.out.println("Creating cache ...It will take some time..");
    Cache cache = new CacheFactory().set(MCAST_PORT, "0").set(DISTRIBUTED_SYSTEM_ID, "" + 1).set(LOCATORS, "localhost[" + 10101 + "]").set(START_LOCATOR, "localhost[" + 10101 + "],server=true,peer=true,hostname-for-clients=localhost").set(LOG_LEVEL, "warning").create();
    System.out.println("Cache Created");
    // to create region and a gateway sender ask to run
    // WANBootStrapping_Site2_Add program
    System.out.println("Run WANBootStrapping_Site2_Add");
    // get the region
    Region region = cache.getRegion("MyRegion");
    while (region == null) {
        region = cache.getRegion("MyRegion");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    // put data in region
    for (int i = 0; i < 100; i++) {
        System.out.println("Create Entry : key_" + i + ", value_" + i);
        region.put("key_" + i, "value_" + i);
    }
    System.out.println("Entry Create Operation completed");
    Set<GatewaySender> gatewaySenders = cache.getGatewaySenders();
    GatewaySender sender = gatewaySenders.iterator().next();
    // make sure that gateway sender is running
    if (sender.isRunning()) {
        System.out.println("Sender " + sender.getId() + " is running");
    }
    // to stop gateway sender ask to run WANBootStrapping_Site2_Remove program
    while (sender.isRunning()) {
        System.out.println("Waitng for sender to stop through DistributedSystemListener");
        System.out.println("Start WANBootStrapping_Site2_Remove");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    System.out.println("Sender " + sender.getId() + " is stopped");
    System.exit(0);
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) Region(org.apache.geode.cache.Region) 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