diff --git a/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/CDITestCheckpoint.java b/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/CDITestCheckpoint.java index 76c58d995a7..682e39be4c8 100644 --- a/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/CDITestCheckpoint.java +++ b/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/CDITestCheckpoint.java @@ -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; @@ -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 { @@ -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 diff --git a/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/DynamicConfigRule.java b/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/DynamicConfigRule.java index 269468556ba..6da9a2799c8 100644 --- a/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/DynamicConfigRule.java +++ b/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/DynamicConfigRule.java @@ -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 { diff --git a/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/FATSuite.java b/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/FATSuite.java index 822701c6e60..1ced2355142 100644 --- a/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/FATSuite.java +++ b/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/FATSuite.java @@ -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; @@ -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 @@ -55,6 +66,7 @@ CDITestCheckpoint.class, ChunkTest.class, JdbcConfigTest.class, + JdbcConfigTestCheckpoint.class, LocalServerJobRecoveryAtStartUpTest.class, MiscTest.class, TranTimeoutTest.class, @@ -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 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, ""); + } + } + } diff --git a/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/JPAPersistenceManagerImplTest.java b/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/JPAPersistenceManagerImplTest.java index deb555d4152..0819a25b88c 100755 --- a/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/JPAPersistenceManagerImplTest.java +++ b/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/JPAPersistenceManagerImplTest.java @@ -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; @@ -37,6 +38,7 @@ 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; @@ -44,6 +46,7 @@ import componenttest.topology.utils.HttpUtils; import componenttest.topology.utils.HttpUtils.HTTPRequestMethod; +@RunWith(FATRunner.class) @Mode(TestMode.FULL) public class JPAPersistenceManagerImplTest extends BatchFATHelper { diff --git a/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/JdbcConfigTestCheckpoint.java b/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/JdbcConfigTestCheckpoint.java new file mode 100644 index 00000000000..5028a5afd9c --- /dev/null +++ b/dev/com.ibm.ws.jbatch.open_fat/fat/src/batch/fat/junit/JdbcConfigTestCheckpoint.java @@ -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 initialSetup = new Callable() { + @Override + public Void call() throws Exception { + setup(); + return null; + } + }; + + /** + * Used with DynamicConfigRule. + */ + public static Callable finalTearDown = new Callable() { + @Override + public Void call() throws Exception { + tearDown(); + return null; + } + }; + + /** + * Used with DynamicConfigRule. Called after each iteration. + */ + public static Callable afterEach = new Callable() { + @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); + } + +} diff --git a/dev/com.ibm.ws.jbatch.open_fat/publish/files/JDBCPersistenceCheckpoint/jdbc.config.myschema1.server.xml b/dev/com.ibm.ws.jbatch.open_fat/publish/files/JDBCPersistenceCheckpoint/jdbc.config.myschema1.server.xml new file mode 100644 index 00000000000..58df95a35d1 --- /dev/null +++ b/dev/com.ibm.ws.jbatch.open_fat/publish/files/JDBCPersistenceCheckpoint/jdbc.config.myschema1.server.xml @@ -0,0 +1,46 @@ + + + + osgiconsole-1.0 + batch-1.0 + servlet-4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/com.ibm.ws.jbatch.open_fat/publish/files/JDBCPersistenceCheckpoint/jdbc.config.myschema1.tp1.server.xml b/dev/com.ibm.ws.jbatch.open_fat/publish/files/JDBCPersistenceCheckpoint/jdbc.config.myschema1.tp1.server.xml new file mode 100644 index 00000000000..645070f5671 --- /dev/null +++ b/dev/com.ibm.ws.jbatch.open_fat/publish/files/JDBCPersistenceCheckpoint/jdbc.config.myschema1.tp1.server.xml @@ -0,0 +1,45 @@ + + + + osgiconsole-1.0 + batch-1.0 + servlet-4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/com.ibm.ws.jbatch.open_fat/publish/files/JDBCPersistenceCheckpoint/jdbc.config.myschema1.tp2.server.xml b/dev/com.ibm.ws.jbatch.open_fat/publish/files/JDBCPersistenceCheckpoint/jdbc.config.myschema1.tp2.server.xml new file mode 100644 index 00000000000..95ec8d476bb --- /dev/null +++ b/dev/com.ibm.ws.jbatch.open_fat/publish/files/JDBCPersistenceCheckpoint/jdbc.config.myschema1.tp2.server.xml @@ -0,0 +1,45 @@ + + + + osgiconsole-1.0 + batch-1.0 + servlet-4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/com.ibm.ws.jbatch.open_fat/publish/files/JDBCPersistenceCheckpoint/jdbc.config.myschema2.server.xml b/dev/com.ibm.ws.jbatch.open_fat/publish/files/JDBCPersistenceCheckpoint/jdbc.config.myschema2.server.xml new file mode 100644 index 00000000000..2f55d56d74a --- /dev/null +++ b/dev/com.ibm.ws.jbatch.open_fat/publish/files/JDBCPersistenceCheckpoint/jdbc.config.myschema2.server.xml @@ -0,0 +1,45 @@ + + + + osgiconsole-1.0 + batch-1.0 + servlet-4.0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dev/com.ibm.ws.jbatch.open_fat/publish/servers/batchFAT/bootstrap.properties b/dev/com.ibm.ws.jbatch.open_fat/publish/servers/batchFAT/bootstrap.properties index 14c1daf4706..1a7fd0487b4 100644 --- a/dev/com.ibm.ws.jbatch.open_fat/publish/servers/batchFAT/bootstrap.properties +++ b/dev/com.ibm.ws.jbatch.open_fat/publish/servers/batchFAT/bootstrap.properties @@ -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