use of org.apache.geode.cache.CacheExistsException in project geode by apache.
the class LRUClockJUnitTest method getARegion.
private Region getARegion() throws Exception {
DistributedSystem ds = DistributedSystem.connect(sysProps);
Cache c = null;
try {
c = CacheFactory.create(ds);
} catch (CacheExistsException cee) {
c = CacheFactory.getInstance(ds);
}
AttributesFactory af = new AttributesFactory();
Region root = c.getRegion("root");
if (root == null) {
root = c.createRegion("root", af.create());
}
Region sub = root.createSubregion(testName.getMethodName(), af.create());
return sub;
}
use of org.apache.geode.cache.CacheExistsException in project geode by apache.
the class JUnit4CacheTestCase method createLonerCache.
/**
* Creates the {@code Cache} for this test that is not connected to other members.
*/
public final Cache createLonerCache() {
synchronized (JUnit4CacheTestCase.class) {
try {
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE", "true");
InternalCache newCache = (InternalCache) CacheFactory.create(getLonerSystem());
cache = newCache;
} catch (CacheExistsException e) {
// TODO: remove error handling
Assert.fail("the cache already exists", e);
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
Assert.fail("Checked exception while initializing cache??", ex);
} finally {
System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE");
}
return cache;
}
}
use of org.apache.geode.cache.CacheExistsException in project geode by apache.
the class JUnit4CacheTestCase method createCache.
private final void createCache(final boolean client, final CacheFactory factory) {
synchronized (JUnit4CacheTestCase.class) {
try {
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE", "true");
InternalCache newCache;
if (client) {
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "locators", "");
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT, "0");
newCache = (InternalCache) new ClientCacheFactory(getSystem().getProperties()).create();
} else {
if (factory == null) {
newCache = (InternalCache) CacheFactory.create(getSystem());
} else {
Properties props = getSystem().getProperties();
for (Map.Entry entry : props.entrySet()) {
factory.set((String) entry.getKey(), (String) entry.getValue());
}
newCache = (InternalCache) factory.create();
}
}
cache = newCache;
} catch (CacheExistsException e) {
// TODO: remove error handling
Assert.fail("the cache already exists", e);
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
Assert.fail("Checked exception while initializing cache??", ex);
} finally {
System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE");
System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + "locators");
System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + MCAST_PORT);
}
}
}
use of org.apache.geode.cache.CacheExistsException in project geode by apache.
the class CacheJUnitTest method testScenario5.
/**
* Test of testScenario5 method, of class org.apache.geode.internal.jta.functional.CacheTest1.
* Tests whether a user transaction with cache lookup and with XAPooledDataSOurce supports Cache
* put and get operations accordingly along with JTA behavior. Put and get are done within the
* transaction block and also db updates are done. We try to rollback the transaction by violating
* primary key constraint in db table, nad then we check whether rollback was proper in db and
* also in Cache, which should also rollback.
*/
@Test
public void testScenario5() throws Exception {
this.tblIDFld = 5;
this.tblNameFld = "test5";
boolean rollback_chances = false;
final String DEFAULT_RGN = "root";
JTAUtils jtaObj = new JTAUtils(cache, currRegion);
jtaObj.deleteRows(this.tblName);
Context ctx = cache.getJNDIContext();
UserTransaction ta = (UserTransaction) ctx.lookup("java:/UserTransaction");
Connection conn = null;
try {
String current_region = jtaObj.currRegion.getName();
assertEquals("default region is not root", DEFAULT_RGN, current_region);
// trying to create a region 'region1' under /root, if it doesn't exist.
// And point to the new region...
jtaObj.getRegionFromCache("region1");
// now current region should point to region1, as done from within
// getRegionFromCache method...
String current_fullpath = jtaObj.currRegion.getFullPath();
assertEquals("failed retirieving current fullpath", "/" + DEFAULT_RGN + "/region1", current_fullpath);
jtaObj.put("key1", "test");
ta.begin();
jtaObj.put("key1", "value1");
String str = jtaObj.get("key1");
String tok = jtaObj.parseGetValue(str);
assertEquals("get value mismatch with put", "\"value1\"", tok);
current_fullpath = jtaObj.currRegion.getFullPath();
assertEquals("failed retrieving current fullpath, current fullpath: " + current_fullpath, "/" + DEFAULT_RGN + "/region1", current_fullpath);
DataSource da = (DataSource) ctx.lookup("java:/XAPooledDataSource");
conn = da.getConnection();
Statement stmt = conn.createStatement();
String sqlSTR = "insert into " + this.tblName + " values (" + this.tblIDFld + "," + "'" + this.tblNameFld + "'" + ")";
stmt.executeUpdate(sqlSTR);
rollback_chances = true;
// capable of throwing SQLException during insert operation
sqlSTR = "insert into " + this.tblName + " values (" + this.tblIDFld + "," + "'" + this.tblNameFld + "'" + ")";
stmt.executeUpdate(sqlSTR);
stmt.close();
ta.commit();
conn.close();
} catch (CacheExistsException e) {
ta.rollback();
fail("test failed " + e.getMessage());
} catch (NamingException e) {
ta.rollback();
fail("test failed " + e.getMessage());
} catch (SQLException e) {
// exception thrown during inserts are handeled as below by rollback
if (rollback_chances) {
try {
ta.rollback();
} catch (Exception ex) {
fail("failed: " + ex.getMessage());
}
// intended error is checked w.r.t database first
int ifAnyRows = 0;
try {
ifAnyRows = jtaObj.getRows(this.tblName);
} catch (Exception ex) {
fail(" failed: " + ex.getMessage());
}
assertEquals("rows found after rollback is: " + ifAnyRows, 0, ifAnyRows);
/*
* if (ifAnyRows != 0) { fail (" DB FAILURE"); }
*/
// intended error is checked w.r.t. cache second
String current_fullpath = jtaObj.currRegion.getFullPath();
assertEquals("failed retrieving current fullpath after rollback, fullpath is: " + current_fullpath, "/" + DEFAULT_RGN + "/region1", current_fullpath);
// after jdbc rollback, cache value in region1 for key1 must vanish...
String str1 = null;
try {
str1 = jtaObj.get("key1");
} catch (CacheException ex) {
fail("failed getting value for 'key1': " + ex.getMessage());
}
String tok1 = jtaObj.parseGetValue(str1);
assertEquals("value found in cache: " + tok1 + ", after rollback", "\"test\"", tok1);
} else {
fail(" failed: " + e.getMessage());
ta.rollback();
}
} catch (Exception e) {
ta.rollback();
fail(" failed: " + e.getMessage());
} finally {
if (conn != null)
try {
conn.close();
} catch (SQLException ex) {
fail("Exception: " + ex.getMessage());
}
}
}
use of org.apache.geode.cache.CacheExistsException in project geode by apache.
the class ConcurrentIndexUpdateWithInplaceObjectModFalseDUnitTest method getAvailableCacheElseCreateCache.
private void getAvailableCacheElseCreateCache() {
synchronized (ConcurrentIndexUpdateWithInplaceObjectModFalseDUnitTest.class) {
try {
Cache newCache = GemFireCacheImpl.getInstance();
if (null == newCache) {
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE", "true");
newCache = CacheFactory.create(getSystem());
}
PRQueryDUnitHelper.setCache(newCache);
} catch (CacheExistsException e) {
// TODO: remove error handling
Assert.fail("the cache already exists", e);
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
Assert.fail("Checked exception while initializing cache??", ex);
} finally {
System.clearProperty(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE");
}
}
}
Aggregations