use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class PdxAttributesJUnitTest method testPdxTypeIdWithNegativeDsId.
@Test
public void testPdxTypeIdWithNegativeDsId() throws Exception {
// in this case geode will use 0 as dsId
int dsId = -1;
CacheFactory cf = new CacheFactory();
cf.set(MCAST_PORT, "0");
cf.set(ConfigurationProperties.DISTRIBUTED_SYSTEM_ID, String.valueOf(dsId));
Cache cache = cf.create();
// define a type.
defineAType();
Region pdxRegion = cache.getRegion(PeerTypeRegistration.REGION_NAME);
Iterator itr = pdxRegion.entrySet().iterator();
boolean found = false;
boolean foundEnum = false;
while (itr.hasNext()) {
Map.Entry ent = (Map.Entry) itr.next();
if (ent.getKey() instanceof Integer) {
int pdxTypeId = (int) ent.getKey();
PdxType pdxType = (PdxType) ent.getValue();
int pdxTypeHashcode = pdxType.hashCode();
System.out.println("pdx hashcode " + pdxTypeHashcode);
int expectedPdxTypeId = PeerTypeRegistration.PLACE_HOLDER_FOR_TYPE_ID & pdxTypeHashcode;
assertEquals(expectedPdxTypeId, pdxTypeId);
found = true;
} else {
EnumId enumId = (EnumId) ent.getKey();
EnumInfo enumInfo = (EnumInfo) ent.getValue();
EnumInfo expectedEnumInfo = new EnumInfo(SimpleEnum.TWO);
int expectKey = PeerTypeRegistration.PLACE_HOLDER_FOR_TYPE_ID & expectedEnumInfo.hashCode();
;
assertEquals(expectKey, enumId.intValue());
foundEnum = true;
}
}
assertEquals(true, found);
cache.close();
}
use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class PdxAttributesJUnitTest method testPdxDiskStore.
@Test
public void testPdxDiskStore() throws Exception {
{
CacheFactory cf = new CacheFactory();
cf.set(MCAST_PORT, "0");
cf.setPdxPersistent(true);
cf.setPdxDiskStore("diskstore1");
Cache cache = cf.create();
cache.createDiskStoreFactory().setDiskDirs(new File[] { diskDir }).setMaxOplogSize(1).create("diskstore1");
// define a type.
defineAType();
Region pdxRegion = cache.getRegion(PeerTypeRegistration.REGION_NAME);
assertEquals("diskstore1", pdxRegion.getAttributes().getDiskStoreName());
cache.close();
}
tearDown();
setUp();
{
CacheFactory cf = new CacheFactory();
cf.set(MCAST_PORT, "0");
cf.setPdxPersistent(true);
Cache cache = cf.create();
// define a type
defineAType();
Region pdxRegion = cache.getRegion(PeerTypeRegistration.REGION_NAME);
assertEquals(DataPolicy.PERSISTENT_REPLICATE, pdxRegion.getAttributes().getDataPolicy());
cache.close();
}
}
use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class PdxClientServerDUnitTest method createServerRegion.
private int createServerRegion(final Class constraintClass) throws IOException {
CacheFactory cf = new CacheFactory(getDistributedSystemProperties());
Cache cache = getCache(cf);
RegionFactory rf = cache.createRegionFactory(RegionShortcut.REPLICATE);
rf.setValueConstraint(constraintClass);
rf.create("testSimplePdx");
CacheServer server = cache.addCacheServer();
int port = AvailablePortHelper.getRandomAvailableTCPPort();
server.setPort(port);
server.start();
return port;
}
use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class PdxTypeExportDUnitTest method loadCache.
@SuppressWarnings("serial")
public void loadCache() throws Exception {
SerializableCallable peer = new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer());
Cache cache = getCache(cf);
Region r = cache.createRegionFactory(RegionShortcut.REPLICATE).create("pdxtest");
r.put(1, new MyObjectPdx(1, "test", MyEnumPdx.const1));
return null;
}
};
final Host host = Host.getHost(0);
host.getVM(1).invoke(peer);
SerializableCallable server = new SerializableCallable() {
@Override
public Object call() throws Exception {
CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer());
CacheServer server = getCache().addCacheServer();
int port = AvailablePortHelper.getRandomAvailableTCPPort();
server.setPort(port);
server.start();
Region r = getCache().createRegionFactory(RegionShortcut.REPLICATE).create("pdxtest");
return port;
}
};
final int port = (Integer) host.getVM(2).invoke(server);
SerializableCallable client = new SerializableCallable() {
@Override
public Object call() throws Exception {
ClientCacheFactory cf = new ClientCacheFactory().setPdxSerializer(new MyPdxSerializer()).addPoolServer(NetworkUtils.getServerHostName(host), port);
ClientCache cache = getClientCache(cf);
Region r = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create("pdxtest");
return null;
}
};
host.getVM(3).invoke(client);
peer.call();
}
use of org.apache.geode.cache.CacheFactory in project geode by apache.
the class AuthJUnitTest method testAuthNoPwd.
@Test
public void testAuthNoPwd() {
CacheFactory cf = new CacheFactory();
cf.set(LOG_LEVEL, "error");
cf.set(MCAST_PORT, "0");
cf.set(LOCATORS, "");
cache = cf.create();
server = new GeodeRedisServer("localhost", port);
server.start();
Exception ex = null;
try {
jedis.auth(PASSWORD);
} catch (JedisDataException e) {
ex = e;
}
assertNotNull(ex);
}
Aggregations