Skip to content

Commit d24c2c8

Browse files
committed
Fix Checkstyle violations & RMI tests
* Increase latch timeouts for `RedisLockRegistryLeaderInitiatorTests` * Some RMI tests fail with different outcome because an RMI registry might be available on default `1099` port. Fix them to not rely on that port
1 parent 3a846ba commit d24c2c8

File tree

6 files changed

+24
-23
lines changed

6 files changed

+24
-23
lines changed

spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonPresent.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2019 the original author or authors.
2+
* Copyright 2017-2020 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.
@@ -42,6 +42,7 @@ public static boolean isJackson2Present() {
4242
}
4343

4444
/**
45+
* @return true if Jackson 1.x is present on classpath
4546
* @deprecated Jackson 1.x is not supported any more. Use Jackson 2.x.
4647
*/
4748
@Deprecated

spring-integration-core/src/main/java/org/springframework/integration/util/SimplePool.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.apache.commons.logging.Log;
2929
import org.apache.commons.logging.LogFactory;
3030

31-
import org.springframework.lang.Nullable;
3231
import org.springframework.util.Assert;
3332

3433
/**

spring-integration-file/src/test/java/org/springframework/integration/file/splitter/FileSplitterTests.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ void testFileSplitter() throws Exception {
116116
assertThat(receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_SIZE)).isEqualTo(2);
117117
assertThat(receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER)).isEqualTo(1);
118118
assertThat(this.selector.accept(receive)).isTrue();
119-
assertThat(this.store.get(this.file.getAbsolutePath())).isEqualTo("1");
119+
assertThat(this.store.get(file.getAbsolutePath())).isEqualTo("1");
120120
receive = this.output.receive(10000);
121121
assertThat(receive).isNotNull(); //äöüß
122122
assertThat(receive.getPayload()).isEqualTo("äöüß");
@@ -125,7 +125,7 @@ void testFileSplitter() throws Exception {
125125
assertThat(receive.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER)).isEqualTo(2);
126126
assertThat(this.output.receive(1)).isNull();
127127
assertThat(this.selector.accept(receive)).isTrue();
128-
assertThat(this.store.get(this.file.getAbsolutePath())).isEqualTo("2");
128+
assertThat(this.store.get(file.getAbsolutePath())).isEqualTo("2");
129129
assertThat(this.selector.accept(receive)).isFalse();
130130

131131
this.input1.send(new GenericMessage<>(file.getAbsolutePath()));
@@ -378,7 +378,7 @@ void testFileReaderClosedOnException() throws Exception {
378378
splitter.setOutputChannel(outputChannel);
379379
FileReader fileReader = Mockito.spy(new FileReader(file));
380380
try {
381-
splitter.handleMessage(new GenericMessage<Reader>(fileReader));
381+
splitter.handleMessage(new GenericMessage<>(fileReader));
382382
}
383383
catch (RuntimeException e) {
384384
// ignore
@@ -421,13 +421,10 @@ public IdempotentReceiverInterceptor idempotentReceiverInterceptor() {
421421
@Bean
422422
public MetadataStoreSelector selector() {
423423
return new MetadataStoreSelector(
424-
message -> message.getHeaders().get(FileHeaders.ORIGINAL_FILE, File.class)
425-
.getAbsolutePath(),
426-
message -> message.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER)
427-
.toString(),
424+
message -> message.getHeaders().get(FileHeaders.ORIGINAL_FILE, File.class).getAbsolutePath(),
425+
message -> message.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER).toString(),
428426
store())
429-
.compareValues(
430-
(oldVal, newVal) -> Integer.parseInt(oldVal) < Integer.parseInt(newVal));
427+
.compareValues((oldVal, newVal) -> Integer.parseInt(oldVal) < Integer.parseInt(newVal));
431428
}
432429

433430
@Bean

spring-integration-redis/src/test/java/org/springframework/integration/redis/leader/RedisLockRegistryLeaderInitiatorTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2019 the original author or authors.
2+
* Copyright 2016-2020 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.
@@ -72,7 +72,7 @@ public void testDistributedLeaderElection() throws Exception {
7272
initiator.start();
7373
}
7474

75-
assertThat(granted.await(10, TimeUnit.SECONDS)).isTrue();
75+
assertThat(granted.await(60, TimeUnit.SECONDS)).isTrue();
7676

7777
LockRegistryLeaderInitiator initiator1 = countingPublisher.initiator;
7878

@@ -106,8 +106,8 @@ public void testDistributedLeaderElection() throws Exception {
106106

107107
initiator1.getContext().yield();
108108

109-
assertThat(revoked1.await(20, TimeUnit.SECONDS)).isTrue();
110-
assertThat(granted2.await(20, TimeUnit.SECONDS)).isTrue();
109+
assertThat(revoked1.await(60, TimeUnit.SECONDS)).isTrue();
110+
assertThat(granted2.await(60, TimeUnit.SECONDS)).isTrue();
111111

112112
assertThat(initiator2.getContext().isLeader()).isTrue();
113113
assertThat(initiator1.getContext().isLeader()).isFalse();
@@ -117,8 +117,8 @@ public void testDistributedLeaderElection() throws Exception {
117117

118118
initiator2.getContext().yield();
119119

120-
assertThat(revoked2.await(20, TimeUnit.SECONDS)).isTrue();
121-
assertThat(granted1.await(20, TimeUnit.SECONDS)).isTrue();
120+
assertThat(revoked2.await(60, TimeUnit.SECONDS)).isTrue();
121+
assertThat(granted1.await(60, TimeUnit.SECONDS)).isTrue();
122122

123123
assertThat(initiator1.getContext().isLeader()).isTrue();
124124
assertThat(initiator2.getContext().isLeader()).isFalse();
@@ -131,7 +131,7 @@ public void testDistributedLeaderElection() throws Exception {
131131

132132
initiator1.getContext().yield();
133133

134-
assertThat(revoked11.await(10, TimeUnit.SECONDS)).isTrue();
134+
assertThat(revoked11.await(60, TimeUnit.SECONDS)).isTrue();
135135
assertThat(initiator1.getContext().isLeader()).isFalse();
136136

137137
initiator1.stop();

spring-integration-rmi/src/test/java/org/springframework/integration/rmi/RmiOutboundGatewayTests.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,24 @@ public class RmiOutboundGatewayTests {
4646

4747
private static final QueueChannel OUTPUT = new QueueChannel(1);
4848

49+
private static int RMI_PORT;
50+
4951
private static RmiServiceExporter EXPORTER;
5052

5153
private static RmiOutboundGateway GATEWAY;
5254

5355
@BeforeAll
5456
static void setup() throws RemoteException {
55-
int rmiPort = SocketUtils.findAvailableTcpPort();
57+
RMI_PORT = SocketUtils.findAvailableTcpPort();
5658

5759
EXPORTER = new RmiServiceExporter();
5860
EXPORTER.setService(new TestExchanger());
5961
EXPORTER.setServiceInterface(RequestReplyExchanger.class);
6062
EXPORTER.setServiceName("testRemoteHandler");
61-
EXPORTER.setRegistryPort(rmiPort);
63+
EXPORTER.setRegistryPort(RMI_PORT);
6264
EXPORTER.afterPropertiesSet();
6365

64-
GATEWAY = new RmiOutboundGateway("rmi://localhost:" + rmiPort + "/testRemoteHandler");
66+
GATEWAY = new RmiOutboundGateway("rmi://localhost:" + RMI_PORT + "/testRemoteHandler");
6567
GATEWAY.setOutputChannel(OUTPUT);
6668
}
6769

@@ -120,7 +122,7 @@ void nonSerializableAttribute() {
120122

121123
@Test
122124
void invalidServiceName() {
123-
RmiOutboundGateway gateway = new RmiOutboundGateway("rmi://localhost:1099/noSuchService");
125+
RmiOutboundGateway gateway = new RmiOutboundGateway("rmi://localhost:" + RMI_PORT + "/noSuchService");
124126
assertThatExceptionOfType(MessageHandlingException.class)
125127
.isThrownBy(() -> gateway.handleMessage(new GenericMessage<>("test")))
126128
.withCauseInstanceOf(RemoteLookupFailureException.class);
@@ -136,7 +138,7 @@ void invalidHost() {
136138

137139
@Test
138140
void invalidUrl() {
139-
RmiOutboundGateway gateway = new RmiOutboundGateway("invalid");
141+
RmiOutboundGateway gateway = new RmiOutboundGateway("http://sample.com/");
140142
assertThatExceptionOfType(MessageHandlingException.class)
141143
.isThrownBy(() -> gateway.handleMessage(new GenericMessage<>("test")))
142144
.withCauseInstanceOf(RemoteLookupFailureException.class);

spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/DefaultConfigurationTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.integration.test.util.TestUtils;
3030
import org.springframework.messaging.MessageChannel;
3131
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
32+
import org.springframework.test.annotation.DirtiesContext;
3233
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3334
import org.springframework.util.ErrorHandler;
3435

@@ -40,6 +41,7 @@
4041
* @since 1.0.3
4142
*/
4243
@SpringJUnitConfig
44+
@DirtiesContext
4345
public class DefaultConfigurationTests {
4446

4547
@Autowired

0 commit comments

Comments
 (0)