use of org.apache.geode.cache.Cache in project geode by apache.
the class DistributedSystemDUnitTest method testMembershipPortRangeWithExactThreeValues.
@Test
public void testMembershipPortRangeWithExactThreeValues() throws Exception {
Properties config = new Properties();
config.setProperty(LOCATORS, "localhost[" + getDUnitLocatorPort() + "]");
config.setProperty(MEMBERSHIP_PORT_RANGE, this.lowerBoundOfPortRange + "-" + this.upperBoundOfPortRange);
InternalDistributedSystem system = getSystem(config);
Cache cache = CacheFactory.create(system);
cache.addCacheServer();
DistributionManager dm = (DistributionManager) system.getDistributionManager();
InternalDistributedMember member = dm.getDistributionManagerId();
GMSMembershipManager gms = (GMSMembershipManager) MembershipManagerHelper.getMembershipManager(system);
JGroupsMessenger messenger = (JGroupsMessenger) gms.getServices().getMessenger();
String jgConfig = messenger.getJGroupsStackConfig();
assertThat(jgConfig).as("expected to find port_range=\"2\" in " + jgConfig).contains("port_range=\"2\"");
verifyMembershipPortsInRange(member, this.lowerBoundOfPortRange, this.upperBoundOfPortRange);
}
use of org.apache.geode.cache.Cache 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();
}
};
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class CommitFunction method execute.
public void execute(FunctionContext context) {
Cache cache = CacheFactory.getAnyInstance();
TXId txId = null;
try {
txId = (TXId) context.getArguments();
} catch (ClassCastException e) {
logger.info("CommitFunction should be invoked with a TransactionId as an argument i.e. setArguments(txId).execute(function)");
throw e;
}
DistributedMember member = txId.getMemberId();
Boolean result = false;
final boolean isDebugEnabled = logger.isDebugEnabled();
if (cache.getDistributedSystem().getDistributedMember().equals(member)) {
if (isDebugEnabled) {
logger.debug("CommitFunction: for transaction: {} committing locally", txId);
}
CacheTransactionManager txMgr = cache.getCacheTransactionManager();
if (txMgr.tryResume(txId)) {
if (isDebugEnabled) {
logger.debug("CommitFunction: resumed transaction: {}", txId);
}
txMgr.commit();
result = true;
}
} else {
ArrayList args = new ArrayList();
args.add(txId);
args.add(NestedTransactionFunction.COMMIT);
Execution ex = FunctionService.onMember(member).setArguments(args);
if (isDebugEnabled) {
logger.debug("CommitFunction: for transaction: {} executing NestedTransactionFunction on member: {}", txId, member);
}
try {
List list = (List) ex.execute(new NestedTransactionFunction()).getResult();
result = (Boolean) list.get(0);
} catch (FunctionException fe) {
if (fe.getCause() instanceof FunctionInvocationTargetException) {
throw new TransactionDataNodeHasDepartedException("Could not commit on member:" + member);
} else {
throw fe;
}
}
}
if (isDebugEnabled) {
logger.debug("CommitFunction: for transaction: {} returning result: {}", txId, result);
}
context.getResultSender().lastResult(result);
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class DeltaFaultInDUnitTest method test.
@Test
public void test() throws Exception {
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final boolean copyOnRead = false;
final boolean clone = true;
SerializableCallable createDataRegion = new SerializableCallable("createDataRegion") {
public Object call() throws Exception {
Cache cache = getCache();
cache.setCopyOnRead(copyOnRead);
cache.createDiskStoreFactory().create("DeltaFaultInDUnitTestData");
AttributesFactory attr = new AttributesFactory();
attr.setDiskStoreName("DeltaFaultInDUnitTestData");
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
attr.setCloningEnabled(clone);
attr.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK));
Region region = cache.createRegion("region1", attr.create());
return null;
}
};
vm0.invoke(createDataRegion);
SerializableRunnable createEmptyRegion = new SerializableRunnable("createEmptyRegion") {
public void run() {
Cache cache = getCache();
cache.setCopyOnRead(copyOnRead);
AttributesFactory<Integer, TestDelta> attr = new AttributesFactory<Integer, TestDelta>();
attr.setCloningEnabled(clone);
PartitionAttributesFactory<Integer, TestDelta> paf = new PartitionAttributesFactory<Integer, TestDelta>();
paf.setRedundantCopies(1);
paf.setLocalMaxMemory(0);
PartitionAttributes<Integer, TestDelta> prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
attr.setDataPolicy(DataPolicy.PARTITION);
attr.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK));
Region<Integer, TestDelta> region = cache.createRegion("region1", attr.create());
// Put an entry
region.put(new Integer(0), new TestDelta(false, "initial"));
// Put a delta object that is larger
region.put(new Integer(0), new TestDelta(true, "initial_plus_some_more_data"));
}
};
vm1.invoke(createEmptyRegion);
vm0.invoke(new SerializableRunnable("doPut") {
public void run() {
Cache cache = getCache();
Region<Integer, TestDelta> region = cache.getRegion("region1");
// Evict the other object
region.put(new Integer(113), new TestDelta(false, "bogus"));
// Something was going weird with the LRU list. It was evicting this object.
// I want to make sure the other object is the one evicted.
region.get(new Integer(113));
long entriesEvicted = ((AbstractLRURegionMap) ((PartitionedRegion) region).entries)._getLruList().stats().getEvictions();
// assertIndexDetailsEquals(1, entriesEvicted);
TestDelta result = region.get(new Integer(0));
assertEquals("initial_plus_some_more_data", result.info);
}
});
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class EventTrackerDUnitTest method checkReplicateEventTracker.
private SerializableRunnable checkReplicateEventTracker(VM vm, final int expectedEntryCount) {
SerializableRunnable checkEventTracker = new SerializableRunnable("checkEventTracker") {
public void run() {
Cache cache = getCache();
DistributedRegion region = (DistributedRegion) cache.getRegion("replicate");
checkEventTracker(region, expectedEntryCount);
}
};
vm.invoke(checkEventTracker);
return checkEventTracker;
}
Aggregations