|
1 | 1 | /*
|
2 |
| - * Copyright 2020-2021 the original author or authors. |
| 2 | + * Copyright 2020-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -110,6 +110,36 @@ public void testDateMillisecondPrecision() throws Exception {
|
110 | 110 | Assert.assertEquals(2, jobExecutions.size());
|
111 | 111 | }
|
112 | 112 |
|
| 113 | + /* |
| 114 | + * This test is for issue https://github.com/spring-projects/spring-batch/issues/4087: |
| 115 | + * A round trip from a `java.lang.Long` or `java.lang.Double` JobParameter that value is null to the database and back |
| 116 | + * again should preserve null. otherwise a different |
| 117 | + * job instance is created while the existing one should be used. |
| 118 | + * |
| 119 | + * This test ensures that round trip to the database with a `java.lang.Long` or `java.lang.Double` |
| 120 | + * parameter that value is null ends up with a single job instance (with two job executions) |
| 121 | + * being created and not two distinct job instances (with a job execution for |
| 122 | + * each one). |
| 123 | + * |
| 124 | + */ |
| 125 | + @Test |
| 126 | + public void testLongOrDoubleNullable() throws Exception { |
| 127 | + // given |
| 128 | + JobParameters jobParameters = new JobParametersBuilder() |
| 129 | + .addLong("attribute", null) // as same as Double type |
| 130 | + .toJobParameters(); |
| 131 | + |
| 132 | + // when |
| 133 | + JobExecution jobExecution = this.jobLauncher.run(this.job, jobParameters); |
| 134 | + this.jobOperator.restart(jobExecution.getId()); // should load the null value for java.lang.Long or java.lang.Double |
| 135 | + |
| 136 | + // then |
| 137 | + List<Long> jobInstances = this.jobOperator.getJobInstances("job", 0, 100); |
| 138 | + Assert.assertEquals(1, jobInstances.size()); |
| 139 | + List<Long> jobExecutions = this.jobOperator.getExecutions(jobInstances.get(0)); |
| 140 | + Assert.assertEquals(2, jobExecutions.size()); |
| 141 | + } |
| 142 | + |
113 | 143 | @Configuration
|
114 | 144 | @EnableBatchProcessing
|
115 | 145 | static class TestConfiguration {
|
|
0 commit comments