Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JDBC Checkpoint Batch test #29773

Draft
wants to merge 1 commit into
base: integration
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
CDITestCheckpoint.class,
ChunkTest.class,
JdbcConfigTest.class,
JdbcConfigTestCheckpoint.class,
LocalServerJobRecoveryAtStartUpTest.class,
MiscTest.class,
TranTimeoutTest.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package batch.fat.junit;

import java.util.concurrent.Callable;

import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.ibm.websphere.simplicity.log.Log;

import batch.fat.util.BatchFATHelper;
import componenttest.annotation.CheckpointTest;

import com.ibm.ws.jbatch.test.BatchAppUtils;
import com.ibm.ws.jbatch.test.FatUtils;

import componenttest.custom.junit.runner.FATRunner;
import componenttest.topology.impl.LibertyServerFactory;
import io.openliberty.checkpoint.spi.CheckpointPhase;

/**
*
* Test dynamic updates to JDBC config using various schemas and tablePrefixes.
*
*/
@RunWith(FATRunner.class)
@CheckpointTest
public class JdbcConfigTestCheckpoint extends BatchFATHelper {

/**
* Used with DynamicConfigRule.
*/
public static Callable<Void> initialSetup = new Callable<Void>() {
@Override
public Void call() throws Exception {
setup();
return null;
}
};

/**
* Used with DynamicConfigRule.
*/
public static Callable<Void> finalTearDown = new Callable<Void>() {
@Override
public Void call() throws Exception {
tearDown();
return null;
}
};

/**
* Used with DynamicConfigRule. Called after each iteration.
*/
public static Callable<Void> afterEach = new Callable<Void>() {
@Override
public Void call() throws Exception {
afterEach();
return null;
}
};

/**
* This ClassRule will run all the tests in this class multiple times, against
* all the given server.xml configuration files.
*
* Use setInitialSetup/setFinalTearDown to run logic before/after ALL
* tests (against all configurations) have run.
*/
@ClassRule
public static DynamicConfigRule dynamicConfigRule = new DynamicConfigRule().setServer(server).setInitialSetup(initialSetup).setFinalTearDown(finalTearDown).setAfterEach(afterEach).addServerXml("JDBCPersistenceCheckpoint/jdbc.config.myschema1.server.xml").addServerXml("JDBCPersistenceCheckpoint/jdbc.config.myschema2.server.xml").addServerXml("JDBCPersistenceCheckpoint/jdbc.config.myschema1.tp1.server.xml").addServerXml("JDBCPersistenceCheckpoint/jdbc.config.myschema1.tp2.server.xml");

/**
* Start the server and setup the DB.
*/
public static void setup() throws Exception {

log("setup", "start server and execute DDLs");

server = LibertyServerFactory.getLibertyServer("batchFAT");
BatchAppUtils.addDropinsBatchFATWar(server);
BatchAppUtils.addDropinsBonusPayoutWar(server);
BatchAppUtils.addDropinsDbServletAppWar(server);

// Start server
server.setServerConfigurationFile("JDBCPersistenceCheckpoint/jdbc.config.myschema1.server.xml");
server.setCheckpoint(CheckpointPhase.AFTER_APP_START, true, null);
server.startServer("JdbcConfig.log");
server.waitForStringInLog("CWWKF0011I", 20000);
FatUtils.waitForSmarterPlanet(server);

// Setup chunk test data
executeSql("jdbc/batch", getChunkInTableSql());
executeSql("jdbc/batch", getChunkOutTableSql("APP.OUT4"));

executeSql("jdbc/myds", getChunkInTableSql());
executeSql("jdbc/myds", getChunkOutTableSql("APP.OUT1"));
executeSql("jdbc/myds", getChunkOutTableSql("APP.OUT2"));

executeSql("jdbc/mydsNonTran", getChunkInTableSql());
executeSql("jdbc/mydsNonTran", getChunkOutTableSql("APP.OUT3"));
}

/**
* Stop the server.
*/
public static void tearDown() throws Exception {
log("tearDown", "stopping server");
if (server != null && server.isStarted()) {
server.stopServer();
}
}

/**
* Clear out the OUT4 table used by the chunk tests.
*/
public static void afterEach() throws Exception {
log("afterEach", "");
executeSql(DFLT_PERSISTENCE_JNDI, "DELETE FROM APP.OUT4;");
}

/**
* Test a simple batchlet.
*/
@Test
public void testBasicJDBCPersistence() throws Exception {
test("Basic", "jslName=BasicPersistence");
}

/**
* Chunk test using the same datasource as the batch tables.
*/
@Test
public void testSharedResourceMultiChunk() throws Exception {
test("Chunk", "jslName=ChunkTestMultipleCheckpoint&writeTable=APP.OUT4&sharedDB=true");
}

/**
* Log helper.
*/
public static void log(String method, String msg) {
Log.info(JdbcConfigTestCheckpoint .class, method, msg);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<server>

<featureManager>
<feature>osgiconsole-1.0</feature>
<feature>batch-1.0</feature>
<feature>servlet-3.1</feature>
</featureManager>

<include location="../fatTestPorts.xml"/>

<!-- Configured with schema -->
<batchPersistence jobStoreRef="BatchDatabaseStore" />

<databaseStore id="BatchDatabaseStore" dataSourceRef="batchDB" schema="MYSCHEMA1" tablePrefix="" />

<!-- The derby driver -->
<library id="DerbyLib">
<file name="${shared.resource.dir}/derby/derby.jar"/>
</library>

<!-- The following configures in-memory Derby. For Derby on disk, which is needed if the database
is required beyond a single server start, configure the databaseName with a file location such as:
databaseName="${shared.config.dir}/data/derbydb" -->

<!-- Derby datasource used for batch tables-->
<dataSource id="batchDB" jndiName="jdbc/batch" type="javax.sql.XADataSource">
<jdbcDriver libraryRef="DerbyLib"/>
<properties.derby.embedded createDatabase="create" databaseName="memory:JdbcConfigTestCheckpointDb" user="user" password="pass" />
</dataSource>

<!-- Derby datasource used by chunk tests, transactional -->
<dataSource jndiName="jdbc/myds" type="javax.sql.XADataSource">
<jdbcDriver libraryRef="DerbyLib"/>
<properties.derby.embedded createDatabase="create" databaseName="memory:ChunkTestTwoResources" user="user" password="pass" />
</dataSource>

<!-- Derby datasource used by chunk tests, non-transactional -->
<dataSource jndiName="jdbc/mydsNonTran" type="javax.sql.ConnectionPoolDataSource" transactional="false">
<jdbcDriver libraryRef="DerbyLib"/>
<properties.derby.embedded createDatabase="create" databaseName="memory:ChunkTestTwoResourcesNonTran" user="user" password="pass" />
</dataSource>

<javaPermission className="java.util.PropertyPermission" name="*" actions="read"/>
<javaPermission className="java.security.AllPermission" codebase="${shared.resource.dir}/derby/derby.jar"/>

</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<server>

<featureManager>
<feature>osgiconsole-1.0</feature>
<feature>batch-1.0</feature>
<feature>servlet-3.1</feature>
</featureManager>

<include location="../fatTestPorts.xml"/>

<!-- Configured with schema -->
<batchPersistence jobStoreRef="BatchDatabaseStore" />

<databaseStore id="BatchDatabaseStore" dataSourceRef="batchDB" schema="MYSCHEMA1" tablePrefix="TP1_"/>

<!-- The derby driver -->
<library id="DerbyLib">
<file name="${shared.resource.dir}/derby/derby.jar"/>
</library>

<!-- The following configures in-memory Derby. For Derby on disk, which is needed if the database
is required beyond a single server start, configure the databaseName with a file location such as:
databaseName="${shared.config.dir}/data/derbydb" -->

<!-- Derby datasource used for batch tables-->
<dataSource id="batchDB" jndiName="jdbc/batch" type="javax.sql.XADataSource">
<jdbcDriver libraryRef="DerbyLib"/>
<properties.derby.embedded createDatabase="create" databaseName="memory:JdbcConfigTestCheckpointDb" user="user" password="pass" />
</dataSource>

<!-- Derby datasource used by chunk tests, transactional -->
<dataSource jndiName="jdbc/myds" type="javax.sql.XADataSource">
<jdbcDriver libraryRef="DerbyLib"/>
<properties.derby.embedded createDatabase="create" databaseName="memory:ChunkTestTwoResources" user="user" password="pass" />
</dataSource>

<!-- Derby datasource used by chunk tests, non-transactional -->
<dataSource jndiName="jdbc/mydsNonTran" type="javax.sql.ConnectionPoolDataSource" transactional="false">
<jdbcDriver libraryRef="DerbyLib"/>
<properties.derby.embedded createDatabase="create" databaseName="memory:ChunkTestTwoResourcesNonTran" user="user" password="pass" />
</dataSource>

<javaPermission className="java.util.PropertyPermission" name="*" actions="read"/>

</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<server>

<featureManager>
<feature>osgiconsole-1.0</feature>
<feature>batch-1.0</feature>
<feature>servlet-3.1</feature>
</featureManager>

<include location="../fatTestPorts.xml"/>

<!-- Configured with schema -->
<batchPersistence jobStoreRef="BatchDatabaseStore" />

<databaseStore id="BatchDatabaseStore" dataSourceRef="batchDB" schema="MYSCHEMA1" tablePrefix="TP2_"/>

<!-- The following configures in-memory Derby. For Derby on disk, which is needed if the database
is required beyond a single server start, configure the databaseName with a file location such as:
databaseName="${shared.config.dir}/data/derbydb" -->

<!-- The derby driver -->
<library id="DerbyLib">
<file name="${shared.resource.dir}/derby/derby.jar"/>
</library>

<!-- Derby datasource used for batch tables-->
<dataSource id="batchDB" jndiName="jdbc/batch" type="javax.sql.XADataSource">
<jdbcDriver libraryRef="DerbyLib"/>
<properties.derby.embedded createDatabase="create" databaseName="memory:JdbcConfigTestCheckpointDb" user="user" password="pass" />
</dataSource>

<!-- Derby datasource used by chunk tests, transactional -->
<dataSource jndiName="jdbc/myds" type="javax.sql.XADataSource">
<jdbcDriver libraryRef="DerbyLib"/>
<properties.derby.embedded createDatabase="create" databaseName="memory:ChunkTestTwoResources" user="user" password="pass" />
</dataSource>

<!-- Derby datasource used by chunk tests, non-transactional -->
<dataSource jndiName="jdbc/mydsNonTran" type="javax.sql.ConnectionPoolDataSource" transactional="false">
<jdbcDriver libraryRef="DerbyLib"/>
<properties.derby.embedded createDatabase="create" databaseName="memory:ChunkTestTwoResourcesNonTran" user="user" password="pass" />
</dataSource>

<javaPermission className="java.util.PropertyPermission" name="*" actions="read"/>

</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<server>

<featureManager>
<feature>osgiconsole-1.0</feature>
<feature>batch-1.0</feature>
<feature>servlet-3.1</feature>
</featureManager>

<include location="../fatTestPorts.xml"/>

<!-- Configured with schema -->
<batchPersistence jobStoreRef="BatchDatabaseStore" />

<databaseStore id="BatchDatabaseStore" dataSourceRef="batchDB" schema="MYSCHEMA2" tablePrefix="" />

<!-- The derby driver -->
<library id="DerbyLib">
<file name="${shared.resource.dir}/derby/derby.jar"/>
</library>

<!-- The following configures in-memory Derby. For Derby on disk, which is needed if the database
is required beyond a single server start, configure the databaseName with a file location such as:
databaseName="${shared.config.dir}/data/derbydb" -->

<!-- Derby datasource used for batch tables-->
<dataSource id="batchDB" jndiName="jdbc/batch" type="javax.sql.XADataSource">
<jdbcDriver libraryRef="DerbyLib"/>
<properties.derby.embedded createDatabase="create" databaseName="memory:JdbcConfigTestCheckpointDb" user="user" password="pass" />
</dataSource>

<!-- Derby datasource used by chunk tests, transactional -->
<dataSource jndiName="jdbc/myds" type="javax.sql.XADataSource">
<jdbcDriver libraryRef="DerbyLib"/>
<properties.derby.embedded createDatabase="create" databaseName="memory:ChunkTestTwoResources" user="user" password="pass" />
</dataSource>

<!-- Derby datasource used by chunk tests, non-transactional -->
<dataSource jndiName="jdbc/mydsNonTran" type="javax.sql.ConnectionPoolDataSource" transactional="false">
<jdbcDriver libraryRef="DerbyLib"/>
<properties.derby.embedded createDatabase="create" databaseName="memory:ChunkTestTwoResourcesNonTran" user="user" password="pass" />
</dataSource>


<javaPermission className="java.util.PropertyPermission" name="*" actions="read"/>
</server>
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ com.ibm.ws.logging.trace.specification=*=info=enabled\

bootstrap.include=../testports.properties
osgi.console=5678
io.openliberty.checkpoint.allowed.features=batch-1.0,batch-2.0,batch-2.1,batch-management-1.0