Fix new Sonar smells; optimize some tests

This commit is contained in:
Artem Bilan
2021-02-24 11:34:29 -05:00
parent a0093f016d
commit eef31d4b34
5 changed files with 45 additions and 26 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@@ -435,7 +435,7 @@ public class CachingClientConnectionFactoryTests {
}
@Test
// @Repeat(1000) // INT-3722
// @Repeat(1000) // INT-3722
public void gatewayIntegrationTest() throws Exception {
final List<String> connectionIds = new ArrayList<>();
final AtomicBoolean okToRun = new AtomicBoolean(true);
@@ -497,6 +497,7 @@ public class CachingClientConnectionFactoryTests {
TcpConnection connection = cccf.getConnection();
await().atMost(Duration.ofSeconds(10)).until(() -> !connection.isOpen());
cccf.stop();
cccf.destroy();
}
@Test
@@ -526,6 +527,9 @@ public class CachingClientConnectionFactoryTests {
conn1 = cachingFactory.getConnection();
conn1.send(message);
Mockito.verify(mockConn2).send(message);
conn1.close();
cachingFactory.stop();
cachingFactory.destroy();
}
@Test
@@ -592,6 +596,8 @@ public class CachingClientConnectionFactoryTests {
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
SimplePool<?> pool = TestUtils.getPropertyValue(cachingFactory, "pool", SimplePool.class);
assertThat(pool.getIdleCount()).isEqualTo(2);
cachingFactory.stop();
cachingFactory.destroy();
server2.stop();
}
@@ -650,6 +656,8 @@ public class CachingClientConnectionFactoryTests {
assertThat(latch1.getCount()).isEqualTo(3);
server1.stop();
server2.stop();
cachingFactory.stop();
cachingFactory.destroy();
}
@Test //INT-3650
@@ -689,6 +697,7 @@ public class CachingClientConnectionFactoryTests {
assertThat(connectionIds.get(101)).isSameAs(connectionIds.get(0));
in.stop();
cache.stop();
cache.destroy();
}
@SuppressWarnings("unchecked")
@@ -721,11 +730,12 @@ public class CachingClientConnectionFactoryTests {
TcpNetClientConnectionFactory out = new TcpNetClientConnectionFactory("localhost", port);
out.setApplicationEventPublisher(mock(ApplicationEventPublisher.class));
CachingClientConnectionFactory cache = new CachingClientConnectionFactory(out, 2);
final TcpOutboundGateway gate = new TcpOutboundGateway();
TcpOutboundGateway gate = new TcpOutboundGateway();
gate.setConnectionFactory(cache);
QueueChannel outputChannel = new QueueChannel();
gate.setOutputChannel(outputChannel);
gate.setBeanFactory(mock(BeanFactory.class));
gate.setRemoteTimeout(20_000);
gate.afterPropertiesSet();
LogAccessor logger = spy(TestUtils.getPropertyValue(gate, "logger", LogAccessor.class));
new DirectFieldAccessor(gate).setPropertyValue("logger", logger);
@@ -761,6 +771,8 @@ public class CachingClientConnectionFactoryTests {
handler.stop();
gate.stop();
verify(logger, never()).error(anyString());
cache.stop();
in.stop();
}
@Test // INT-3728