Skip to content

Commit a34a627

Browse files
committed
Adjust test logging for less noise during build
* Resolve deprecations in the `RetryContextSerializationTests`
1 parent b98b2a5 commit a34a627

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

src/test/java/org/springframework/retry/policy/RetryContextSerializationTests.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2023 the original author or authors.
2+
* Copyright 2006-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,9 @@
1616

1717
package org.springframework.retry.policy;
1818

19+
import java.io.ByteArrayInputStream;
20+
import java.io.IOException;
21+
import java.io.ObjectInputStream;
1922
import java.util.ArrayList;
2023
import java.util.List;
2124
import java.util.Set;
@@ -42,13 +45,13 @@
4245
/**
4346
* @author Dave Syer
4447
* @author Gary Russell
48+
* @author Artem Bilan
4549
*
4650
*/
4751
public class RetryContextSerializationTests {
4852

4953
private static final Log logger = LogFactory.getLog(RetryContextSerializationTests.class);
5054

51-
@SuppressWarnings("deprecation")
5255
public static List<Object[]> policies() {
5356
List<Object[]> result = new ArrayList<>();
5457
ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
@@ -58,11 +61,11 @@ public static List<Object[]> policies() {
5861
Set<BeanDefinition> candidates = scanner.findCandidateComponents("org.springframework.retry.policy");
5962
for (BeanDefinition beanDefinition : candidates) {
6063
try {
61-
result.add(new Object[] {
62-
BeanUtils.instantiate(ClassUtils.resolveClassName(beanDefinition.getBeanClassName(), null)) });
64+
result.add(new Object[] { BeanUtils
65+
.instantiateClass(ClassUtils.resolveClassName(beanDefinition.getBeanClassName(), null)) });
6366
}
6467
catch (Exception e) {
65-
logger.warn("Cannot create instance of " + beanDefinition.getBeanClassName(), e);
68+
logger.info("Cannot create instance of " + beanDefinition.getBeanClassName(), e);
6669
}
6770
}
6871
ExceptionClassifierRetryPolicy extra = new ExceptionClassifierRetryPolicy();
@@ -71,25 +74,35 @@ public static List<Object[]> policies() {
7174
return result;
7275
}
7376

74-
@SuppressWarnings("deprecation")
7577
@ParameterizedTest
7678
@MethodSource("policies")
7779
public void testSerializationCycleForContext(RetryPolicy policy) {
7880
RetryContext context = policy.open(null);
7981
assertThat(context.getRetryCount()).isEqualTo(0);
8082
policy.registerThrowable(context, new RuntimeException());
8183
assertThat(context.getRetryCount()).isEqualTo(1);
82-
assertThat(
83-
((RetryContext) SerializationUtils.deserialize(SerializationUtils.serialize(context))).getRetryCount())
84-
.isEqualTo(1);
84+
assertThat(deserialize(SerializationUtils.serialize(context))).extracting("retryCount").isEqualTo(1);
8585
}
8686

8787
@ParameterizedTest
8888
@MethodSource("policies")
89-
@SuppressWarnings("deprecation")
9089
public void testSerializationCycleForPolicy(RetryPolicy policy) {
91-
assertThat(SerializationUtils.deserialize(SerializationUtils.serialize(policy)) instanceof RetryPolicy)
92-
.isTrue();
90+
assertThat(deserialize(SerializationUtils.serialize(policy)) instanceof RetryPolicy).isTrue();
91+
}
92+
93+
private static Object deserialize(byte[] bytes) {
94+
if (bytes == null) {
95+
return null;
96+
}
97+
try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes))) {
98+
return ois.readObject();
99+
}
100+
catch (IOException ex) {
101+
throw new IllegalArgumentException("Failed to deserialize object", ex);
102+
}
103+
catch (ClassNotFoundException ex) {
104+
throw new IllegalStateException("Failed to deserialize object type", ex);
105+
}
93106
}
94107

95108
}

src/test/resources/log4j2-test.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
</Console>
77
</Appenders>
88
<Loggers>
9-
<Logger name="org.springframework.context" level="warn"/>
10-
<Logger name="org.springframework.retry" level="info"/>
11-
<Logger name="org.springframework.transaction" level="info"/>
12-
<Root level="info">
9+
<Logger name="org.springframework" level="warn"/>
10+
<Logger name="org.springframework.retry" level="warn"/>
11+
<Root level="warn">
1312
<AppenderRef ref="STDOUT" />
1413
</Root>
1514
</Loggers>

0 commit comments

Comments
 (0)