Skip to content

Commit

Permalink
Add JDBC Checkpoint Batch test
Browse files Browse the repository at this point in the history
  • Loading branch information
SmithaSubbarao committed Oct 17, 2024
1 parent 16635fd commit 7db99d4
Show file tree
Hide file tree
Showing 10 changed files with 375 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import batch.fat.util.BatchFATHelper;
import componenttest.annotation.CheckpointTest;
import componenttest.custom.junit.runner.FATRunner;
import componenttest.topology.impl.LibertyServer;
import componenttest.topology.impl.LibertyServerFactory;
import io.openliberty.checkpoint.spi.CheckpointPhase;

Expand All @@ -34,6 +35,8 @@
public class CDITestCheckpoint extends BatchFATHelper {

private static final Class testClass = CDITestCheckpoint.class;
// save off the original server value so it can be restored after class
private static final LibertyServer superServer = BatchFATHelper.server;

@BeforeClass
public static void setup() throws Exception {
Expand All @@ -54,6 +57,8 @@ public static void tearDown() throws Exception {
if (server != null && server.isStarted()) {
server.stopServer("CWWKY0041W");
}
// restore back to original server
server = superServer;
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ protected void iterateServerXmls() throws Throwable {

server.setMarkToEndOfLog();
server.setServerConfigurationFile(serverXmlFileName);
// start server & checkpoint
// stop server, copy in next server.xml config
// restore
server.waitForConfigUpdateInLogUsingMark(null);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
*******************************************************************************/
package batch.fat.junit;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
import java.util.Properties;

import org.junit.ClassRule;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
Expand All @@ -22,6 +32,7 @@
import componenttest.rules.repeater.JakartaEE10Action;
import componenttest.rules.repeater.JakartaEE9Action;
import componenttest.rules.repeater.RepeatTests;
import componenttest.topology.impl.LibertyServer;

/**
* Collection of all example tests
Expand Down Expand Up @@ -55,6 +66,7 @@
CDITestCheckpoint.class,
ChunkTest.class,
JdbcConfigTest.class,
JdbcConfigTestCheckpoint.class,
LocalServerJobRecoveryAtStartUpTest.class,
MiscTest.class,
TranTimeoutTest.class,
Expand All @@ -70,4 +82,19 @@ public class FATSuite {
public static RepeatTests r = RepeatTests.with(new EmptyAction().fullFATOnly())
.andWith(new JakartaEE9Action().conditionalFullFATOnly(FeatureReplacementAction.GREATER_THAN_OR_EQUAL_JAVA_11))
.andWith(new JakartaEE10Action());

static public void configureBootStrapProperties(LibertyServer server, Map<String, String> properties) throws Exception, IOException, FileNotFoundException {
Properties bootStrapProperties = new Properties();
File bootStrapPropertiesFile = new File(server.getFileFromLibertyServerRoot("bootstrap.properties").getAbsolutePath());
if (bootStrapPropertiesFile.isFile()) {
try (InputStream in = new FileInputStream(bootStrapPropertiesFile)) {
bootStrapProperties.load(in);
}
}
bootStrapProperties.putAll(properties);
try (OutputStream out = new FileOutputStream(bootStrapPropertiesFile)) {
bootStrapProperties.store(out, "");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.ibm.websphere.simplicity.log.Log;
import com.ibm.ws.common.encoder.Base64Coder;
Expand All @@ -37,13 +38,15 @@

import batch.fat.util.BatchFATHelper;
import componenttest.annotation.ExpectedFFDC;
import componenttest.custom.junit.runner.FATRunner;
import componenttest.custom.junit.runner.Mode;
import componenttest.custom.junit.runner.Mode.TestMode;
import componenttest.topology.impl.LibertyServer;
import componenttest.topology.impl.LibertyServerFactory;
import componenttest.topology.utils.HttpUtils;
import componenttest.topology.utils.HttpUtils.HTTPRequestMethod;

@RunWith(FATRunner.class)
@Mode(TestMode.FULL)
public class JPAPersistenceManagerImplTest extends BatchFATHelper {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package batch.fat.junit;

import java.util.Collections;
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);

// Disabling security test for checkpoint
FATSuite.configureBootStrapProperties(server, Collections.singletonMap("websphere.java.security.exempt","true"));

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

// Apply config and restore
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,47 @@
<server>

<featureManager>
<feature>osgiconsole-1.0</feature>
<feature>batch-1.0</feature>
<feature>servlet-3.1</feature>
<feature>servlet-4.0</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,46 @@
<server>

<featureManager>
<feature>osgiconsole-1.0</feature>
<feature>batch-1.0</feature>
<feature>servlet-3.1</feature>
<feature>servlet-4.0</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>
Loading

0 comments on commit 7db99d4

Please sign in to comment.