use of org.apache.geode.cache.CacheExistsException in project geode by apache.
the class DiskStoreCommands method alterOfflineDiskStore.
@CliCommand(value = CliStrings.ALTER_DISK_STORE, help = CliStrings.ALTER_DISK_STORE__HELP)
@CliMetaData(shellOnly = true, relatedTopic = { CliStrings.TOPIC_GEODE_DISKSTORE })
public Result alterOfflineDiskStore(@CliOption(key = CliStrings.ALTER_DISK_STORE__DISKSTORENAME, mandatory = true, help = CliStrings.ALTER_DISK_STORE__DISKSTORENAME__HELP) String diskStoreName, @CliOption(key = CliStrings.ALTER_DISK_STORE__REGIONNAME, mandatory = true, help = CliStrings.ALTER_DISK_STORE__REGIONNAME__HELP) String regionName, @CliOption(key = CliStrings.ALTER_DISK_STORE__DISKDIRS, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__DISKDIRS__HELP, mandatory = true) String[] diskDirs, @CliOption(key = CliStrings.ALTER_DISK_STORE__COMPRESSOR, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, specifiedDefaultValue = "none", help = CliStrings.ALTER_DISK_STORE__COMPRESSOR__HELP) String compressorClassName, @CliOption(key = CliStrings.ALTER_DISK_STORE__CONCURRENCY__LEVEL, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__CONCURRENCY__LEVEL__HELP) Integer concurrencyLevel, @CliOption(key = CliStrings.ALTER_DISK_STORE__STATISTICS__ENABLED, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__STATISTICS__ENABLED__HELP) Boolean statisticsEnabled, @CliOption(key = CliStrings.ALTER_DISK_STORE__INITIAL__CAPACITY, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__INITIAL__CAPACITY__HELP) Integer initialCapacity, @CliOption(key = CliStrings.ALTER_DISK_STORE__LOAD__FACTOR, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__LOAD__FACTOR__HELP) Float loadFactor, @CliOption(key = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ACTION, help = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ACTION__HELP) String lruEvictionAction, @CliOption(key = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ALGORITHM, help = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ALGORITHM__HELP) String lruEvictionAlgo, @CliOption(key = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__LIMIT, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__LRU__EVICTION__LIMIT__HELP) Integer lruEvictionLimit, @CliOption(key = CliStrings.ALTER_DISK_STORE__OFF_HEAP, unspecifiedDefaultValue = CliMetaData.ANNOTATION_NULL_VALUE, help = CliStrings.ALTER_DISK_STORE__OFF_HEAP__HELP) Boolean offHeap, @CliOption(key = CliStrings.ALTER_DISK_STORE__REMOVE, help = CliStrings.ALTER_DISK_STORE__REMOVE__HELP, mandatory = false, specifiedDefaultValue = "true", unspecifiedDefaultValue = "false") boolean remove) {
Result result = null;
try {
File[] dirs = null;
if (diskDirs != null) {
dirs = new File[diskDirs.length];
for (int i = 0; i < diskDirs.length; i++) {
dirs[i] = new File((diskDirs[i]));
}
}
if (regionName.equals(Region.SEPARATOR)) {
return ResultBuilder.createUserErrorResult(CliStrings.INVALID_REGION_NAME);
}
if ((lruEvictionAlgo != null) || (lruEvictionAction != null) || (lruEvictionLimit != null) || (concurrencyLevel != null) || (initialCapacity != null) || (loadFactor != null) || (compressorClassName != null) || (offHeap != null) || (statisticsEnabled != null)) {
if (!remove) {
String lruEvictionLimitString = lruEvictionLimit == null ? null : lruEvictionLimit.toString();
String concurrencyLevelString = concurrencyLevel == null ? null : concurrencyLevel.toString();
String initialCapacityString = initialCapacity == null ? null : initialCapacity.toString();
String loadFactorString = loadFactor == null ? null : loadFactor.toString();
String statisticsEnabledString = statisticsEnabled == null ? null : statisticsEnabled.toString();
String offHeapString = offHeap == null ? null : offHeap.toString();
if ("none".equals(compressorClassName)) {
compressorClassName = "";
}
String resultMessage = DiskStoreImpl.modifyRegion(diskStoreName, dirs, "/" + regionName, lruEvictionAlgo, lruEvictionAction, lruEvictionLimitString, concurrencyLevelString, initialCapacityString, loadFactorString, compressorClassName, statisticsEnabledString, offHeapString, false);
result = ResultBuilder.createInfoResult(resultMessage);
} else {
result = ResultBuilder.createParsingErrorResult("Cannot use the --remove=true parameter with any other parameters");
}
} else {
if (remove) {
DiskStoreImpl.destroyRegion(diskStoreName, dirs, "/" + regionName);
result = ResultBuilder.createInfoResult("The region " + regionName + " was successfully removed from the disk store " + diskStoreName);
} else {
// Please provide an option
result = ResultBuilder.createParsingErrorResult("Please provide a relevant parameter");
}
}
// Catch the IllegalArgumentException thrown by the modifyDiskStore function and sent the
} catch (IllegalArgumentException e) {
String message = "Please check the parameters";
message += "\n" + e.getMessage();
result = ResultBuilder.createGemFireErrorResult(message);
} catch (IllegalStateException e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
} catch (CacheExistsException e) {
// Indicates that the command is being used when a cache is open
result = ResultBuilder.createGemFireErrorResult("Cannot execute " + CliStrings.ALTER_DISK_STORE + " when a cache exists (Offline command)");
} catch (Exception e) {
result = createErrorResult(e.getMessage());
}
return result;
}
use of org.apache.geode.cache.CacheExistsException in project geode by apache.
the class CacheJUnitTest method testScenario3.
/**
* Test of testScenario3 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. Put and get are done within the transaction block and also
* db updates are done. After committing we check whether commit is proper in db and also in
* Cache.
*/
@Test
public void testScenario3() throws Exception {
this.tblIDFld = 3;
this.tblNameFld = "test3";
boolean rollback_chances = true;
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 {
/** begin the transaction **/
ta.begin();
String current_region = jtaObj.currRegion.getName();
assertEquals("the default region is not root", DEFAULT_RGN, current_region);
jtaObj.getRegionFromCache("region1");
String current_fullpath = jtaObj.currRegion.getFullPath();
assertEquals("failed retrieving current region fullpath", "/" + DEFAULT_RGN + "/region1", current_fullpath);
jtaObj.put("key1", "value1");
String str = jtaObj.get("key1");
String tok = jtaObj.parseGetValue(str);
assertEquals("get failed for corresponding put", "\"value1\"", tok);
current_fullpath = jtaObj.currRegion.getFullPath();
assertEquals("failed retrieving current region 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);
stmt.close();
ta.commit();
conn.close();
rollback_chances = false;
current_fullpath = jtaObj.currRegion.getFullPath();
assertEquals("failed retrieving current region fullpath after txn commit", "/" + DEFAULT_RGN + "/region1", current_fullpath);
int ifAnyRows = jtaObj.getRows(this.tblName);
assertEquals("rows retrieved is:" + ifAnyRows, 1, ifAnyRows);
/*
* if (ifAnyRows == 0) { fail (" DB FAILURE: no rows retrieved even after txn commit."); }
*/
// after jdbc commit cache value in region1 for key1 must retain...
str = jtaObj.get("key1");
tok = jtaObj.parseGetValue(str);
assertEquals("cache put didn't commit, value retrieved is: " + tok, "\"value1\"", tok);
} catch (CacheExistsException e) {
ta.rollback();
fail(" test 3 failed ");
} catch (NamingException e) {
if (rollback_chances)
ta.rollback();
fail(" test 3 failed " + e.getMessage());
} catch (SQLException e) {
if (rollback_chances)
ta.rollback();
fail(" test 3 failed " + e.getMessage());
} catch (Exception e) {
if (rollback_chances)
ta.rollback();
fail(" test 3 failed " + e.getMessage());
} finally {
if (conn != null)
try {
conn.close();
} catch (SQLException e) {
}
}
}
use of org.apache.geode.cache.CacheExistsException in project geode by apache.
the class CacheJUnitTest method testScenario4.
/**
* Test of testScenario4 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. After rollback the transaction explicitly we
* check whether it was proper in db and also in Cache, which should also rollback.
*/
@Test
public void testScenario4() throws Exception {
this.tblIDFld = 4;
this.tblNameFld = "test4";
boolean rollback_chances = true;
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);
jtaObj.getRegionFromCache("region1");
String current_fullpath = jtaObj.currRegion.getFullPath();
assertEquals("failed retrieving current region fullpath after doing getRegionFromCache(region1)", "/" + 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 do not match with the put", "\"value1\"", tok);
current_fullpath = jtaObj.currRegion.getFullPath();
assertEquals("failed retrieving current region 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);
stmt.close();
ta.rollback();
conn.close();
rollback_chances = false;
current_fullpath = jtaObj.currRegion.getFullPath();
assertEquals("failed retirieving current region fullpath after txn rollback", "/" + DEFAULT_RGN + "/region1", current_fullpath);
int ifAnyRows = jtaObj.getRows(this.tblName);
assertEquals("rows retrieved is: " + ifAnyRows, 0, ifAnyRows);
/*
* if (ifAnyRows != 0) { fail (" DB FAILURE"); }
*/
str = jtaObj.get("key1");
tok = jtaObj.parseGetValue(str);
assertEquals("value existing in cache is: " + tok, "\"test\"", tok);
} catch (CacheExistsException e) {
ta.rollback();
fail(" failed " + e.getMessage());
} catch (NamingException e) {
if (rollback_chances)
ta.rollback();
fail(" failed " + e.getMessage());
} catch (SQLException e) {
if (rollback_chances)
ta.rollback();
fail(" failed " + e.getMessage());
} catch (Exception e) {
if (rollback_chances)
ta.rollback();
fail(" failed " + e.getMessage());
} finally {
if (conn != null)
try {
conn.close();
} catch (SQLException e) {
}
}
}
use of org.apache.geode.cache.CacheExistsException in project geode by apache.
the class CacheJUnitTest method testScenario7.
/**
* Test of testScenario7 method, of class org.apache.geode.internal.jta.functional.CacheTest1.
* Tests a user transaction with cache lookup and with XAPooledDataSource lookup. It does get and
* put operations on the cache within the transaction block and checks whether these operations
* are committed once the transaction is committed.
*/
@Test
public void testScenario7() throws Exception {
this.tblIDFld = 7;
this.tblNameFld = "test7";
boolean rollback_chances = true;
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 {
ta.begin();
String current_region = jtaObj.currRegion.getName();
assertEquals("default region is not root", DEFAULT_RGN, current_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 retrieving the current region fullpath", "/" + DEFAULT_RGN + "/region1", current_fullpath);
jtaObj.put("key1", "value1");
// try to get value1 from key1 in the same region
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 region fullpath", "/" + DEFAULT_RGN + "/region1", current_fullpath);
DataSource da = (DataSource) ctx.lookup("java:/XAPooledDataSource");
conn = da.getConnection();
ta.commit();
conn.close();
rollback_chances = false;
current_fullpath = jtaObj.currRegion.getFullPath();
assertEquals("failed retrieving current region fullpath after txn commit, fullpath is: " + current_region, "/" + DEFAULT_RGN + "/region1", current_fullpath);
str = jtaObj.get("key1");
tok = jtaObj.parseGetValue(str);
assertEquals("cache value found is: " + tok, "\"value1\"", tok);
} catch (CacheExistsException e) {
if (rollback_chances)
ta.rollback();
fail(" failed due to: " + e.getMessage());
} catch (NamingException e) {
ta.rollback();
fail(" failed due to: " + e.getMessage());
} catch (SQLException e) {
ta.rollback();
fail(" failed due to: " + e.getMessage());
} catch (Exception e) {
if (rollback_chances)
ta.rollback();
fail(" failed due to: " + e.getMessage());
} finally {
if (conn != null)
try {
conn.close();
} catch (Exception e) {
}
}
}
use of org.apache.geode.cache.CacheExistsException in project geode by apache.
the class PartitionedRegionBucketCreationDistributionDUnitTest method createLonerCacheWithEnforceUniqueHost.
/**
* Creates the <code>Cache</code> for this test that is not connected to other members.
*
* <p>
* Used by test {@link #testEnforceUniqueHostForLonerDistributedSystem()}. Moved from
* DistributedTestCase to this test is the exclusive caller.
*
* <p>
* Added specifically to test scenario of defect #47181.
*/
private Cache createLonerCacheWithEnforceUniqueHost() {
Cache myCache = null;
try {
System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "DISABLE_DISCONNECT_DS_ON_CACHE_CLOSE", "true");
myCache = CacheFactory.create(getLonerSystemWithEnforceUniqueHost());
} catch (CacheExistsException e) {
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 myCache;
}
Aggregations