use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class TestSubscriptionsDUnitTest method createCache.
private Cache createCache(Properties props) throws Exception {
DistributedSystem ds = getSystem(props);
Cache cache = CacheFactory.create(ds);
return cache;
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class DistributedTestUtils method crashDistributedSystem.
/**
* Crash the cache in the given VM in such a way that it immediately stops communicating with
* peers. This forces the VM's membership manager to throw a ForcedDisconnectException by forcibly
* terminating the JGroups protocol stack with a fake EXIT event.
* <p>
*
* NOTE: if you use this method be sure that you clean up the VM before the end of your test with
* disconnectFromDS() or disconnectAllFromDS().
*/
public static boolean crashDistributedSystem(final VM vm) {
return vm.invoke(() -> {
DistributedSystem system = InternalDistributedSystem.getAnyInstance();
crashDistributedSystem(system);
return true;
});
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class IgnoredException method addIgnoredException.
/**
* Log in all VMs, in both the test logger and the GemFire logger the ignored exception string to
* prevent grep logs from complaining. The suspect string is used by the GrepLogs utility and so
* can contain regular expression characters.
*
* @since GemFire 5.7bugfix
* @param suspectString the exception string to expect
* @param vm the VM on which to log the expected exception or null for all VMs
* @return an IgnoredException instance for removal purposes
*/
public static IgnoredException addIgnoredException(final String suspectString, final VM vm) {
final IgnoredException ignoredException = new IgnoredException(suspectString, vm);
final String addMessage = ignoredException.getAddMessage();
@SuppressWarnings("serial") SerializableRunnable addRunnable = new SerializableRunnable(IgnoredException.class.getSimpleName() + " addIgnoredException") {
public void run() {
// TODO: delete use of system.getLogWriter
DistributedSystem system = InternalDistributedSystem.getConnectedInstance();
if (system != null) {
system.getLogWriter().info(addMessage);
}
// TODO: delete use of LogWriterUtils
try {
LogWriterUtils.getLogWriter().info(addMessage);
} catch (Exception noHydraLogger) {
}
logger.info(addMessage);
}
};
try {
addRunnable.run();
} catch (Exception e) {
throw new RuntimeException(e);
}
if (vm != null) {
vm.invoke(addRunnable);
} else {
Invoke.invokeInEveryVM(addRunnable);
}
ignoredExceptions.add(ignoredException);
return ignoredException;
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class ClientToServerDeltaDUnitTest method createCache.
/*
* create cache with properties
*/
private void createCache(Properties props) throws Exception {
DistributedSystem ds = getSystem(props);
cache = CacheFactory.create(ds);
assertNotNull(cache);
logger = cache.getLoggerI18n();
}
use of org.apache.geode.distributed.DistributedSystem in project geode by apache.
the class DataSourceJTAJUnitTest method testInsertUpdateOnSimpleAndXAdsRollback.
/**
* The following test scenario is to test rollback. In this test scenario it is tested that if
* transactions are rolled back then XA datasource transactions should be rolled back andSimple
* datasource transactions should get committed
*/
@Test
public void testInsertUpdateOnSimpleAndXAdsRollback() throws Exception {
Region currRegion = null;
Cache cache;
DistributedSystem ds = null;
int tblIDFld;
String tblNameFld;
String tblName;
String tableName = null;
// boolean to_continue = true;
final int XA_INSERTS = 3;
final int SM_INSERTS = 1;
// call to init method
try {
Properties props = new Properties();
String path = TestUtil.getResourcePath(CacheUtils.class, "cachejta.xml");
props.setProperty(CACHE_XML_FILE, path);
ds = connect(props);
tableName = CacheUtils.init(ds, "JTATest");
System.out.println("Table name: " + tableName);
tblName = tableName;
if (tableName == null || tableName.equals("")) {
// to_continue = false;
fail(" table name not created, Aborting test...");
}
} catch (Exception e) {
// to_continue = false;
fail(" Aborting test at set up...[" + e + "]", e);
}
System.out.println("init for testscenario 2 Successful!");
// test task
cache = CacheUtils.getCache();
tblName = tableName;
currRegion = cache.getRegion("/root");
tblIDFld = 1;
tblNameFld = "test2";
JTAUtils jtaObj = new JTAUtils(cache, currRegion);
// to delete all rows inserted in creatTable () of CacheUtils class
// deleteRows method of JTAUtils class is used.
jtaObj.deleteRows(tblName);
// initialize cache and get user transaction
Context ctx = cache.getJNDIContext();
UserTransaction ta = null;
Connection xa_conn = null;
Connection sm_conn = null;
try {
ta = (UserTransaction) ctx.lookup("java:/UserTransaction");
} catch (NamingException e) {
fail(" fail in user txn lookup ", e);
}
try {
// get the SimpleDataSource before the transaction begins
DataSource sds = (DataSource) ctx.lookup("java:/SimpleDataSource");
// Begin the user transaction
ta.begin();
// Obtain XAPooledDataSource
DataSource da = (DataSource) ctx.lookup("java:/XAPooledDataSource");
// obtain connection from SimpleDataSource and XAPooledDataSource
xa_conn = da.getConnection();
sm_conn = sds.getConnection();
Statement xa_stmt = xa_conn.createStatement();
Statement sm_stmt = sm_conn.createStatement();
// perform inserts and updates using both viz. Simple and XA DataSources
// String sqlSTR = "insert into " + tblName + " values (" + tblIDFld + ","
// + "'" + tblNameFld + "'" + ")" ;
String sqlSTR;
// insert XA_INSERTS rows into timestamped table
for (int i = 0; i < XA_INSERTS; i++) {
tblIDFld = tblIDFld + i;
sqlSTR = "insert into " + tblName + " values (" + tblIDFld + "," + "'" + tblNameFld + "'" + ")";
xa_stmt.executeUpdate(sqlSTR);
}
// insert SM_INSERTS rows into timestamped table
for (int j = 0; j < SM_INSERTS; j++) {
tblIDFld = tblIDFld + j + 1;
sqlSTR = "insert into " + tblName + " values (" + tblIDFld + "," + "'" + tblNameFld + "'" + ")";
sm_stmt.executeUpdate(sqlSTR);
}
// close the Simple and XA statements
xa_stmt.close();
sm_stmt.close();
// close the connections
xa_conn.close();
sm_conn.close();
// rollback the transaction
ta.rollback();
System.out.println("Rows are rolled back in the database");
} catch (SQLException e) {
e.printStackTrace();
} catch (Exception e) {
fail(" failed ", e);
} finally {
if (xa_conn != null) {
try {
// close the connections
xa_conn.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
try {
int num_rows = jtaObj.getRows(tblName);
System.out.println("\nNumber of rows in Table under tests are: " + num_rows);
switch(num_rows) {
case 0:
System.out.println("Both Simple and XA DataSource transactions got rolled back!!");
break;
case SM_INSERTS:
System.out.println("Only Simple DataSource transactions got committed!");
break;
case XA_INSERTS:
System.out.println("Only XA DataSource transactions got committed!");
break;
default:
System.out.println("Looks like that things are messed up...look into it");
}
} catch (SQLException sqle) {
sqle.printStackTrace();
}
System.out.println("test task for testScenario2 Succeessful");
// destroying table
try {
System.out.println("Destroying table: " + tblName);
CacheUtils.destroyTable(tblName);
System.out.println("Closing cache...");
System.out.println("destroyTable for testscenario 2 Successful!");
} catch (Exception e) {
fail(" failed during tear down of this test...", e);
} finally {
CacheUtils.closeCache();
// CacheUtils.ds.disconnect();
ds.disconnect();
}
}
Aggregations