diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/ExitStatusTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/ExitStatusTests.java index 4a63d0cab9..43e73e6f17 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/ExitStatusTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/ExitStatusTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2018 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -226,13 +226,10 @@ public void testUnknownIsRunning() throws Exception { } @Test - public void testSerializable() throws Exception { + public void testSerializable() { ExitStatus status = ExitStatus.EXECUTING.replaceExitCode("FOO"); - byte[] bytes = SerializationUtils.serialize(status); - Object object = SerializationUtils.deserialize(bytes); - assertTrue(object instanceof ExitStatus); - ExitStatus restored = (ExitStatus) object; - assertEquals(status.getExitCode(), restored.getExitCode()); + ExitStatus clone = SerializationUtils.clone(status); + assertEquals(status.getExitCode(), clone.getExitCode()); } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java index 70ebc749b0..3a1694d9b0 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -193,13 +193,13 @@ public void testToStringWithNullJob() throws Exception { @Test public void testSerialization() { - byte[] serialized = SerializationUtils.serialize(execution); - JobExecution deserialize = (JobExecution) SerializationUtils.deserialize(serialized); - assertEquals(execution, deserialize); - assertNotNull(deserialize.createStepExecution("foo")); - assertNotNull(deserialize.getFailureExceptions()); + JobExecution clone = SerializationUtils.clone(execution); + assertEquals(execution, clone); + assertNotNull(clone.createStepExecution("foo")); + assertNotNull(clone.getFailureExceptions()); } + @Test public void testFailureExceptions() { RuntimeException exception = new RuntimeException(); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/JobInstanceTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/JobInstanceTests.java index 056819b170..4cd433243c 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/JobInstanceTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/JobInstanceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,10 +59,7 @@ public void testCreateWithNulls() { @Test public void testSerialization() { instance = new JobInstance(1L, "jobName"); - - byte[] serialized = SerializationUtils.serialize(instance); - - assertEquals(instance, SerializationUtils.deserialize(serialized)); + assertEquals(instance, SerializationUtils.clone(instance)); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/JobParametersTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/JobParametersTests.java index 6cd12d4832..bfb61d8b5c 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/JobParametersTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/JobParametersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2021 the original author or authors. + * Copyright 2008-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; -import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -184,10 +183,7 @@ public void testHashCodeEqualWhenNotEmpty() throws Exception { @Test public void testSerialization() { JobParameters params = getNewParameters(); - - byte[] serialized = SerializationUtils.serialize(params); - - assertEquals(params, SerializationUtils.deserialize(serialized)); + assertEquals(params, SerializationUtils.clone(params)); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java index 313bf1e07f..e01d539fa6 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java @@ -259,18 +259,17 @@ public void testHashCodeViaHashSet() throws Exception { } @Test - public void testSerialization() throws Exception { + public void testSerialization() { ExitStatus status = ExitStatus.NOOP; execution.setExitStatus(status); execution.setExecutionContext(foobarEc); - byte[] serialized = SerializationUtils.serialize(execution); - StepExecution deserialized = (StepExecution) SerializationUtils.deserialize(serialized); + StepExecution clone = SerializationUtils.clone(execution); - assertEquals(execution, deserialized); - assertEquals(status, deserialized.getExitStatus()); - assertNotNull(deserialized.getFailureExceptions()); + assertEquals(execution, clone); + assertEquals(status, clone.getExitStatus()); + assertNotNull(clone.getFailureExceptions()); } @Test diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/Db2JobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/Db2JobRepositoryIntegrationTests.java index 0c9c3926c7..bfacd9ee0a 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/Db2JobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/Db2JobRepositoryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 the original author or authors. + * Copyright 2020-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -97,7 +97,7 @@ public DataSource dataSource() throws Exception { dataSource.setUser(db2.getUsername()); dataSource.setPassword(db2.getPassword()); dataSource.setDriverType(4); - dataSource.setServerName(db2.getContainerIpAddress()); + dataSource.setServerName(db2.getHost()); dataSource.setPortNumber(db2.getMappedPort(Db2Container.DB2_PORT)); dataSource.setSslConnection(false); return dataSource; diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java index c0d02976f9..e9aaf3d4f6 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java @@ -48,7 +48,6 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.EnabledIf; import org.springframework.test.context.junit4.SpringRunner; import org.testcontainers.containers.JdbcDatabaseContainer; @@ -228,7 +227,7 @@ public String getTestQueryString() { @Override public String getJdbcUrl() { - return "jdbc:sap://" + getContainerIpAddress() + ":" + getMappedPort(PORT) + "/"; + return "jdbc:sap://" + getHost() + ":" + getMappedPort(PORT) + "/"; } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/OracleJobRepositoryIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/OracleJobRepositoryIntegrationTests.java index 6651f03edb..20ea0663ea 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/OracleJobRepositoryIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/OracleJobRepositoryIntegrationTests.java @@ -103,7 +103,7 @@ public DataSource dataSource() throws Exception { oracleDataSource.setUser(oracle.getUsername()); oracleDataSource.setPassword(oracle.getPassword()); oracleDataSource.setDatabaseName(oracle.getDatabaseName()); - oracleDataSource.setServerName(oracle.getContainerIpAddress()); + oracleDataSource.setServerName(oracle.getHost()); oracleDataSource.setPortNumber(oracle.getOraclePort()); return oracleDataSource; } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/StepExecutionSerializationUtilsTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/StepExecutionSerializationUtilsTests.java index f12ca4e752..3108eab72b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/StepExecutionSerializationUtilsTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/test/step/StepExecutionSerializationUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ import static org.junit.Assert.assertEquals; -import java.util.concurrent.Callable; import java.util.concurrent.CompletionService; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorCompletionService; @@ -40,11 +39,11 @@ public class StepExecutionSerializationUtilsTests { @Test - public void testCycle() throws Exception { + public void testCycle() { StepExecution stepExecution = new StepExecution("step", new JobExecution(new JobInstance(123L, "job"), 321L, new JobParameters()), 11L); stepExecution.getExecutionContext().put("foo.bar.spam", 123); - StepExecution result = getCopy(stepExecution); + StepExecution result = SerializationUtils.clone(stepExecution); assertEquals(stepExecution, result); } @@ -61,15 +60,12 @@ public void testMultipleCycles() throws Throwable { for (int i = 0; i < repeats; i++) { final JobExecution jobExecution = new JobExecution(new JobInstance(123L, "job"), 321L, new JobParameters()); for (int j = 0; j < threads; j++) { - completionService.submit(new Callable() { - @Override - public StepExecution call() throws Exception { - final StepExecution stepExecution = jobExecution.createStepExecution("step"); - stepExecution.getExecutionContext().put("foo.bar.spam", 123); - StepExecution result = getCopy(stepExecution); - assertEquals(stepExecution.getExecutionContext(), result.getExecutionContext()); - return result; - } + completionService.submit(() -> { + final StepExecution stepExecution = jobExecution.createStepExecution("step"); + stepExecution.getExecutionContext().put("foo.bar.spam", 123); + StepExecution result = SerializationUtils.clone(stepExecution); + assertEquals(stepExecution.getExecutionContext(), result.getExecutionContext()); + return result; }); } for (int j = 0; j < threads; j++) { @@ -97,8 +93,4 @@ public StepExecution call() throws Exception { } } - private StepExecution getCopy(StepExecution stepExecution) { - return (StepExecution) SerializationUtils.deserialize(SerializationUtils.serialize(stepExecution)); - } - } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java index a8f32a0c7e..5c91e45e3b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2018 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -153,12 +153,10 @@ public void testSerialization() { context.put("5", s); context.putInt("6", 6); - byte[] serialized = SerializationUtils.serialize(context); + ExecutionContext clone = SerializationUtils.clone(context); - ExecutionContext deserialized = (ExecutionContext) SerializationUtils.deserialize(serialized); - - assertEquals(context, deserialized); - assertEquals(7, ((TestSerializable) deserialized.get("5")).value); + assertEquals(context, clone); + assertEquals(7, ((TestSerializable) clone.get("5")).value); } @Test diff --git a/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java b/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java index 2dd3bc4874..46e2ddb45f 100644 --- a/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java +++ b/spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,17 +76,6 @@ public static void main(String... args) { DataSourceInitializer.class.getSimpleName() + "-context.xml")); } - /** - * @throws Throwable - * @see java.lang.Object#finalize() - */ - @Override - protected void finalize() throws Throwable { - logger.debug("finalize called for " + dataSource); - super.finalize(); - initialized = false; - } - @Override public void destroy() { logger.info("destroy called for " + dataSource); diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkRequestTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkRequestTests.java index ae273d4594..11067179a8 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkRequestTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkRequestTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,10 +54,8 @@ public void testToString() { } @Test - public void testSerializable() throws Exception { - @SuppressWarnings("unchecked") - ChunkRequest result = (ChunkRequest) SerializationUtils - .deserialize(SerializationUtils.serialize(request)); + public void testSerializable() { + ChunkRequest result = SerializationUtils.clone(request); assertNotNull(result.getStepContribution()); assertEquals(111L, result.getJobId()); assertEquals(2, result.getItems().size()); diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkResponseTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkResponseTests.java index 16eeed4f14..639b2a4328 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkResponseTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkResponseTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,8 +47,8 @@ public void testToString() { } @Test - public void testSerializable() throws Exception { - ChunkResponse result = (ChunkResponse) SerializationUtils.deserialize(SerializationUtils.serialize(response)); + public void testSerializable() { + ChunkResponse result = SerializationUtils.clone(response); assertNotNull(result.getStepContribution()); assertEquals(Long.valueOf(111L), result.getJobId()); }