Skip to content
Permalink
Browse files
Fixed some junit tests to work with JPAPersistenceManagerService
(this includes a JPQL bug fix in CheckpointEntity)
  • Loading branch information
chberger committed Apr 13, 2020
1 parent 3308709 commit 4bf42483e28bea7c4e358a0fbc38ad80e31f74dd
Showing 3 changed files with 22 additions and 18 deletions.
@@ -33,7 +33,7 @@
@NamedQueries({
@NamedQuery(name = CheckpointEntity.Queries.FIND,
query = "select c from CheckpointEntity c where c.instance.jobInstanceId = :jobInstanceId and c.stepName = :stepName and c.type = :type"),
@NamedQuery(name = CheckpointEntity.Queries.DELETE_BY_INSTANCE_ID, query = "delete from CheckpointEntity e where e.instance.jobInstanceId = :id"),
@NamedQuery(name = CheckpointEntity.Queries.DELETE_BY_INSTANCE_ID, query = "delete from CheckpointEntity e where e.instance.jobInstanceId = :instanceId"),
@NamedQuery(
name = CheckpointEntity.Queries.DELETE_BY_DATE,
query = "delete from CheckpointEntity e where (select max(x.endTime) from JobExecutionEntity x where x.instance.jobInstanceId = e.instance.jobInstanceId) < :date")
@@ -34,7 +34,7 @@ public class JobOperatorImplTest {
public void runningExecutionMemory_BATCHEE112() {
final JobOperator operator = new JobOperatorImpl(new ServicesManager() {{
init(new Properties() {{
setProperty(PersistenceManagerService.class.getSimpleName(), MemoryPersistenceManagerService.class.getName());
setProperty(PersistenceManagerService.class.getName(), MemoryPersistenceManagerService.class.getName());
}});
}});
for (int i = 0; i < 10; i++) {
@@ -39,7 +39,9 @@
import static org.testng.Assert.assertNotNull;

public class JMXTest {
private static long id;
private static long executionId;
private static long instanceId;
private static long stepExecutionId;
private static MBeanServer server;
private static ObjectName on;

@@ -51,8 +53,10 @@ public static void createAJob() throws Exception {
final JobOperator jobOperator = BatchRuntime.getJobOperator();
clearPersistence(jobOperator);

id = jobOperator.start("jmx", new Properties() {{ setProperty("foo", "bar"); }});
Batches.waitForEnd(jobOperator, id);
executionId = jobOperator.start("jmx", new Properties() {{ setProperty("foo", "bar"); }});
instanceId = jobOperator.getJobInstance(executionId).getInstanceId();
Batches.waitForEnd(jobOperator, executionId);
stepExecutionId = jobOperator.getStepExecutions(executionId).get(0).getStepExecutionId();
}

private static void clearPersistence(final JobOperator jobOperator) {
@@ -66,7 +70,7 @@ private static void clearPersistence(final JobOperator jobOperator) {

@AfterClass
public static void deleteJob() throws Exception {
ServicesManager.find().service(PersistenceManagerService.class).cleanUp(id);
ServicesManager.find().service(PersistenceManagerService.class).cleanUp(instanceId);
}

private static Object attr(final String name) throws Exception {
@@ -104,14 +108,14 @@ public void jobInstances() throws Exception {
final TabularData instance = TabularData.class.cast(result("getJobInstances", "jmx", 0, 1));
assertEquals(1, instance.size());

final CompositeData cd = instance.get(new Object[]{"jmx", id});
assertEquals(id, cd.get("instanceId"));
final CompositeData cd = instance.get(new Object[]{"jmx", instanceId});
assertEquals(instanceId, cd.get("instanceId"));
assertEquals("jmx", cd.get("jobName"));
}

@Test
public void parameters() throws Exception {
final TabularData instance = TabularData.class.cast(result("getParameters", id));
final TabularData instance = TabularData.class.cast(result("getParameters", executionId));
assertEquals(1, instance.size());

final CompositeData cd = instance.get(List.class.cast(instance.keySet().iterator().next()).toArray());
@@ -121,45 +125,45 @@ public void parameters() throws Exception {

@Test
public void jobInstance() throws Exception {
final TabularData instance = TabularData.class.cast(result("getJobInstance", id));
final TabularData instance = TabularData.class.cast(result("getJobInstance", executionId));
assertEquals(1, instance.size());

final CompositeData cd = instance.get(new Object[]{"jmx", id});
assertEquals(id, cd.get("instanceId"));
final CompositeData cd = instance.get(new Object[]{"jmx", instanceId});
assertEquals(instanceId, cd.get("instanceId"));
assertEquals("jmx", cd.get("jobName"));
}

@Test
public void jobExecutions() throws Exception {
final TabularData instance = TabularData.class.cast(result("getJobExecutions", id, "jmx"));
final TabularData instance = TabularData.class.cast(result("getJobExecutions", instanceId, "jmx"));
assertEquals(1, instance.size());

final CompositeData cd = instance.get(List.class.cast(instance.keySet().iterator().next()).toArray());
assertEquals(id, cd.get("executionId"));
assertEquals(executionId, cd.get("executionId"));
assertEquals("jmx", cd.get("jobName"));
assertEquals("COMPLETED", cd.get("Exit status"));
assertEquals("COMPLETED", cd.get("Batch status"));
}

@Test
public void jobExecution() throws Exception {
final TabularData instance = TabularData.class.cast(result("getJobExecution", id));
final TabularData instance = TabularData.class.cast(result("getJobExecution", executionId));
assertEquals(1, instance.size());

final CompositeData cd = instance.get(List.class.cast(instance.keySet().iterator().next()).toArray());
assertEquals(id, cd.get("executionId"));
assertEquals(executionId, cd.get("executionId"));
assertEquals("jmx", cd.get("jobName"));
assertEquals("COMPLETED", cd.get("Exit status"));
assertEquals("COMPLETED", cd.get("Batch status"));
}

@Test
public void stepExecutions() throws Exception {
final TabularData instance = TabularData.class.cast(result("getStepExecutions", id));
final TabularData instance = TabularData.class.cast(result("getStepExecutions", executionId));
assertEquals(1, instance.size());

final CompositeData cd = instance.get(List.class.cast(instance.keySet().iterator().next()).toArray());
assertEquals(id, cd.get("stepExecutionId"));
assertEquals(stepExecutionId, cd.get("stepExecutionId"));
assertEquals("jmx-step", cd.get("stepName"));
assertEquals("mock", cd.get("Exit status"));
assertEquals("COMPLETED", cd.get("Batch status"));

0 comments on commit 4bf4248

Please sign in to comment.