ARTEMIS-4181 make try-with-resources style consistent

This commit is contained in:
Justin Bertram 2023-02-24 11:01:41 -06:00
parent 5d024b7dd5
commit 97c78525da
23 changed files with 151 additions and 72 deletions

View File

@ -340,7 +340,7 @@ public class Upgrade extends InstallAbstract {
if (!newLogging.exists()) {
context.out.println("Creating " + newLogging);
try (InputStream inputStream = openStream("etc/" + Create.ETC_LOG4J2_PROPERTIES);
OutputStream outputStream = new FileOutputStream(newLogging);) {
OutputStream outputStream = new FileOutputStream(newLogging)) {
copy(inputStream, outputStream);
}
}

View File

@ -134,7 +134,8 @@ public class ServerUtil {
public static boolean waitForServerToStart(String uri, String username, String password, long timeout) throws InterruptedException {
long realTimeout = System.currentTimeMillis() + timeout;
while (System.currentTimeMillis() < realTimeout) {
try (ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory(uri, null); Connection c = cf.createConnection(username, password)) {
try (ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactory(uri, null);
Connection c = cf.createConnection(username, password)) {
System.out.println("server " + uri + " started");
} catch (Exception e) {
System.out.println("awaiting server " + uri + " start at ");

View File

@ -1582,7 +1582,8 @@ public class ArtemisTest extends CliTestBase {
System.setProperty("artemis.instance", instanceQstat.getAbsolutePath());
Artemis.internalExecute("run");
try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection connection = cf.createConnection("admin", "admin");) {
try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection connection = cf.createConnection("admin", "admin")) {
//set up some queues with messages and consumers
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
@ -1858,7 +1859,8 @@ public class ArtemisTest extends CliTestBase {
System.setProperty("artemis.instance", instanceQstat.getAbsolutePath());
Artemis.internalExecute("run");
try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection connection = cf.createConnection("admin", "admin");) {
try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection connection = cf.createConnection("admin", "admin")) {
//set up some queues with messages and consumers
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
@ -2035,7 +2037,8 @@ public class ArtemisTest extends CliTestBase {
System.setProperty("artemis.instance", instanceQstat.getAbsolutePath());
Artemis.internalExecute("run");
try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection connection = cf.createConnection("admin", "admin");) {
try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection connection = cf.createConnection("admin", "admin")) {
TestActionContext context;
StatQueue statQueue;
@ -2119,7 +2122,8 @@ public class ArtemisTest extends CliTestBase {
Artemis.internalExecute("run", "--properties", new File(brokerPropertiesFromClasspath.toURI()).getAbsolutePath());
// verify
try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61618"); Connection connection = cf.createConnection("admin", "admin");) {
try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61618");
Connection connection = cf.createConnection("admin", "admin")) {
connection.start();
} finally {
stopServer();

View File

@ -281,7 +281,8 @@ public class MessageSerializerTest extends CliTestBase {
createQueue(routingType, address, queue1Name);
createQueue(routingType, address, queue2Name);
try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616"); Connection connection = cf.createConnection("admin", "admin");) {
try (ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61616");
Connection connection = cf.createConnection("admin", "admin")) {
// send messages to queue
Session session = createSession(connection);

View File

@ -561,7 +561,8 @@ public class JMSMappingOutboundTransformerTest {
private CoreObjectMessageWrapper createObjectMessage(Serializable payload) {
CoreObjectMessageWrapper result = AMQPMessageSupport.createObjectMessage(0, null);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos);) {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(payload);
byte[] data = baos.toByteArray();
@ -589,7 +590,8 @@ public class JMSMappingOutboundTransformerTest {
}
private Object deserialize(byte[] payload) throws Exception {
try (ByteArrayInputStream bis = new ByteArrayInputStream(payload); ObjectInputStream ois = new ObjectInputStream(bis);) {
try (ByteArrayInputStream bis = new ByteArrayInputStream(payload);
ObjectInputStream ois = new ObjectInputStream(bis)) {
return ois.readObject();
}

View File

@ -865,7 +865,8 @@ public final class OpenWireMessageConverter {
byte[] bytes = new byte[n];
buffer.readBytes(bytes);
if (isCompressed) {
try (ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); DeflaterOutputStream out = new DeflaterOutputStream(bytesOut, true)) {
try (ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
DeflaterOutputStream out = new DeflaterOutputStream(bytesOut, true)) {
out.write(bytes);
out.flush();
bytes = bytesOut.toByteArray();

View File

@ -522,7 +522,8 @@ public class ConfigurationImpl implements Configuration, Serializable {
if (files != null && files.length > 0) {
Arrays.sort(files);
for (String fileName : files) {
try (FileInputStream fileInputStream = new FileInputStream(new File(dir, fileName)); BufferedInputStream reader = new BufferedInputStream(fileInputStream)) {
try (FileInputStream fileInputStream = new FileInputStream(new File(dir, fileName));
BufferedInputStream reader = new BufferedInputStream(fileInputStream)) {
brokerProperties.clear();
brokerProperties.load(reader);
parsePrefixedProperties(fileName, brokerProperties, null);
@ -532,7 +533,8 @@ public class ConfigurationImpl implements Configuration, Serializable {
}
} else {
File file = new File(fileUrl);
try (FileInputStream fileInputStream = new FileInputStream(file); BufferedInputStream reader = new BufferedInputStream(fileInputStream)) {
try (FileInputStream fileInputStream = new FileInputStream(file);
BufferedInputStream reader = new BufferedInputStream(fileInputStream)) {
brokerProperties.load(reader);
parsePrefixedProperties(file.getName(), brokerProperties, null);
}

View File

@ -741,7 +741,8 @@ public final class ReplicationManager implements ActiveMQComponent {
final ReusableLatch flushed = new ReusableLatch(1);
try {
try (FileInputStream fis = new FileInputStream(file.getJavaFile()); FileChannel channel = fis.getChannel()) {
try (FileInputStream fis = new FileInputStream(file.getJavaFile());
FileChannel channel = fis.getChannel()) {
// We cannot afford having a single buffer here for this entire loop
// because sendReplicatePacket will encode the packet as a NettyBuffer

View File

@ -146,7 +146,8 @@ public class PropertiesLoginModuleTest extends Assert {
private String genHash(File usersFile) {
Checksum hash = new Adler32();
try (FileReader fileReader = new FileReader(usersFile); BufferedReader bufferedReader = new BufferedReader(fileReader)) {
try (FileReader fileReader = new FileReader(usersFile);
BufferedReader bufferedReader = new BufferedReader(fileReader)) {
String line = null;
while ((line = bufferedReader.readLine()) != null) {
if (!line.startsWith("#") && !line.isBlank()) {

View File

@ -107,5 +107,7 @@ under the License.
<property name="requiredParameters" value="name"/>
</module>
<module name="UnnecessarySemicolonInTryWithResources"/>
</module>
</module>

View File

@ -279,7 +279,7 @@ public class NettyTransportSupport {
private static KeyStore loadStore(String storePath, final String password, String storeType) throws Exception {
KeyStore store = KeyStore.getInstance(storeType);
try (InputStream in = new FileInputStream(new File(storePath));) {
try (InputStream in = new FileInputStream(new File(storePath))) {
store.load(in, password != null ? password.toCharArray() : null);
}

View File

@ -134,7 +134,10 @@ public class AmqpBridgeApplicationPropertiesTest extends AmqpClientTestSupport {
sendMessages("uswest.Provider.AMC.Agent.f261d0fa-51bd-44bd-abe0-ce22d2a387cd.CustomNotification", 1, RoutingType.ANYCAST, true);
try (ServerLocator locator = ActiveMQClient.createServerLocator(getServer1URL()); ClientSessionFactory sessionFactory = locator.createSessionFactory(); ClientSession session = sessionFactory.createSession(); ClientConsumer consumer = session.createConsumer(notificationsQueue)) {
try (ServerLocator locator = ActiveMQClient.createServerLocator(getServer1URL());
ClientSessionFactory sessionFactory = locator.createSessionFactory();
ClientSession session = sessionFactory.createSession();
ClientConsumer consumer = session.createConsumer(notificationsQueue)) {
session.start();

View File

@ -165,7 +165,10 @@ public class AmqpBridgeClusterRedistributionTest extends AmqpClientTestSupport {
@Test
public void testSendMessageToBroker0GetFromBroker1() throws Exception {
try (ServerLocator locator = ActiveMQClient.createServerLocator(getServer1URL()); ClientSessionFactory sessionFactory = locator.createSessionFactory(); ClientSession session = sessionFactory.createSession(); ClientConsumer consumer = session.createConsumer(notificationsQueue)) {
try (ServerLocator locator = ActiveMQClient.createServerLocator(getServer1URL());
ClientSessionFactory sessionFactory = locator.createSessionFactory();
ClientSession session = sessionFactory.createSession();
ClientConsumer consumer = session.createConsumer(notificationsQueue)) {
session.start();
@ -187,7 +190,10 @@ public class AmqpBridgeClusterRedistributionTest extends AmqpClientTestSupport {
@Test
public void testSendMessageToBroker0GetFromBroker2() throws Exception {
try (ServerLocator locator = ActiveMQClient.createServerLocator(getServer2URL()); ClientSessionFactory sessionFactory = locator.createSessionFactory(); ClientSession session = sessionFactory.createSession(); ClientConsumer consumer = session.createConsumer(notificationsQueue)) {
try (ServerLocator locator = ActiveMQClient.createServerLocator(getServer2URL());
ClientSessionFactory sessionFactory = locator.createSessionFactory();
ClientSession session = sessionFactory.createSession();
ClientConsumer consumer = session.createConsumer(notificationsQueue)) {
session.start();

View File

@ -439,12 +439,16 @@ public class SimpleStreamingLargeMessageTest extends AmqpClientTestSupport {
int MESSAGES = 10;
String producerUri = "amqp://localhost:5672";
final JmsConnectionFactory producerFactory = new JmsConnectionFactory(producerUri);
try (Connection producerConnection = producerFactory.createConnection(); Session producerSession = producerConnection.createSession(tx, tx ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE)) {
try (Connection producerConnection = producerFactory.createConnection();
Session producerSession = producerConnection.createSession(tx, tx ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE)) {
producerConnection.start();
final Destination queue = producerSession.createQueue(getQueueName());
String consumerUri = "amqp://localhost:5672";
final JmsConnectionFactory consumerConnectionFactory = new JmsConnectionFactory(consumerUri);
try (Connection consumerConnection = consumerConnectionFactory.createConnection(); Session consumerSession = consumerConnection.createSession(tx, tx ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = consumerSession.createConsumer(queue); MessageProducer producer = producerSession.createProducer(queue)) {
try (Connection consumerConnection = consumerConnectionFactory.createConnection();
Session consumerSession = consumerConnection.createSession(tx, tx ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = consumerSession.createConsumer(queue);
MessageProducer producer = producerSession.createProducer(queue)) {
if (persistent) {
producer.setDeliveryMode(DeliveryMode.PERSISTENT);
} else {

View File

@ -136,7 +136,8 @@ public class FederatedAddressTest extends FederatedTestBase {
private void verifyTransformer(String address) throws Exception {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection1.start();
connection0.start();
@ -343,7 +344,8 @@ public class FederatedAddressTest extends FederatedTestBase {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection1.start();
connection0.start();
@ -395,7 +397,8 @@ public class FederatedAddressTest extends FederatedTestBase {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection1.start();
connection0.start();
@ -452,7 +455,8 @@ public class FederatedAddressTest extends FederatedTestBase {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection1.start();
connection0.start();
@ -492,7 +496,8 @@ public class FederatedAddressTest extends FederatedTestBase {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection1.start();
connection0.start();
@ -550,7 +555,8 @@ public class FederatedAddressTest extends FederatedTestBase {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection1.start();
connection0.start();
@ -624,7 +630,8 @@ public class FederatedAddressTest extends FederatedTestBase {
ConnectionFactory cf2 = getCF(2);
ConnectionFactory cf0 = getCF(0);
try (Connection connection2 = cf2.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection2 = cf2.createConnection();
Connection connection0 = cf0.createConnection()) {
connection0.start();
Session session0 = connection0.createSession();
Topic topic0 = session0.createTopic(address);

View File

@ -109,7 +109,9 @@ public class FederatedQueueTest extends FederatedTestBase {
ConnectionFactory cf1 = getCF(0);
ConnectionFactory cf2 = getCF(0);
ConnectionFactory cf3 = getCF(1);
try (Connection consumer1Connection = cf1.createConnection(); Connection consumer2Connection = cf2.createConnection(); Connection producerConnection = cf3.createConnection()) {
try (Connection consumer1Connection = cf1.createConnection();
Connection consumer2Connection = cf2.createConnection();
Connection producerConnection = cf3.createConnection()) {
consumer1Connection.start();
Session session1 = consumer1Connection.createSession();
Queue queue1 = session1.createQueue("Test.Q.1");
@ -167,7 +169,8 @@ public class FederatedQueueTest extends FederatedTestBase {
private void testFederatedQueueRemoteConsumeUpstreamPriorityAdjustment(final String queueName) throws Exception {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection0.start();
connection1.start();
Session session0 = connection0.createSession();
@ -197,7 +200,8 @@ public class FederatedQueueTest extends FederatedTestBase {
private void verifyTransformer(String queueName) throws Exception {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection1.start();
Session session1 = connection1.createSession();
Queue queue1 = session1.createQueue(queueName);
@ -254,7 +258,8 @@ public class FederatedQueueTest extends FederatedTestBase {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection1.start();
Session session1 = connection1.createSession();
Queue queue1 = session1.createQueue(queueName);
@ -308,7 +313,8 @@ public class FederatedQueueTest extends FederatedTestBase {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
final String payload = new String(new byte[1 * 1024 * 1024]).replace('\0','+');
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection1.start();
Session session1 = connection1.createSession();
Queue queue1 = session1.createQueue(queueName);
@ -330,7 +336,8 @@ public class FederatedQueueTest extends FederatedTestBase {
ConnectionFactory cf0 = getCF(0);
ConnectionFactory cf1 = getCF(1);
try (Connection connection0 = cf0.createConnection(); Connection connection1 = cf1.createConnection()) {
try (Connection connection0 = cf0.createConnection();
Connection connection1 = cf1.createConnection()) {
connection1.start();
Session session1 = connection1.createSession();
@ -443,7 +450,8 @@ public class FederatedQueueTest extends FederatedTestBase {
private void testFederatedQueueShareUpstreamConnection(String queueName, int server0Connections, int server1Connections) throws Exception {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection0.start();
connection1.start();
Session session0 = connection0.createSession();
@ -462,7 +470,8 @@ public class FederatedQueueTest extends FederatedTestBase {
private void testFederatedQueueBiDirectional(String queueName, boolean shared) throws Exception {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection0.start();
Session session0 = connection0.createSession();
Queue queue0 = session0.createQueue(queueName);
@ -544,7 +553,8 @@ public class FederatedQueueTest extends FederatedTestBase {
ConnectionFactory cf2 = getCF(2);
ConnectionFactory cf0 = getCF(0);
try (Connection connection2 = cf2.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection2 = cf2.createConnection();
Connection connection0 = cf0.createConnection()) {
connection0.start();
Session session0 = connection0.createSession();
Queue queue0 = session0.createQueue(queueName);

View File

@ -34,7 +34,8 @@ public class TopicControlClusterTest extends JMSClusteredTestBase {
final String topicName = "t1";
final SimpleString simpleTopicName = SimpleString.toSimpleString(topicName);
try (Connection conn1 = cf1.createConnection(); Connection conn2 = cf2.createConnection()) {
try (Connection conn1 = cf1.createConnection();
Connection conn2 = cf2.createConnection()) {
conn1.setClientID("someClient1");
conn2.setClientID("someClient2");

View File

@ -3772,7 +3772,9 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
}
// create some consumers
try (ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory csf = createSessionFactory(locator); ClientSession session = csf.createSession()) {
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator);
ClientSession session = csf.createSession()) {
session.start();
ClientConsumer consumer1_q1 = session.createConsumer(queueName1);
@ -3926,7 +3928,9 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
}
// create some consumers
try (ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory csf = createSessionFactory(locator); ClientSession session = csf.createSession()) {
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator);
ClientSession session = csf.createSession()) {
session.start();
ClientConsumer consumer1_q1 = session.createConsumer(queueName1);
@ -4182,7 +4186,9 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
}
// create some consumers
try (ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory csf = createSessionFactory(locator); ClientSession session = csf.createSession()) {
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator);
ClientSession session = csf.createSession()) {
ClientConsumer consumer1_q1 = session.createConsumer(queueName1);
ClientConsumer consumer2_q1 = session.createConsumer(queueName1);
@ -4276,7 +4282,8 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
server.createQueue(new QueueConfiguration(queueName1).setAddress(addressName1).setRoutingType(RoutingType.ANYCAST).setDurable(false));
}
try (ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory csf = createSessionFactory(locator);) {
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator)) {
ClientSessionImpl session1 = (ClientSessionImpl) csf.createSession();
ClientSessionImpl session2 = (ClientSessionImpl) csf.createSession();
@ -4329,7 +4336,8 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
}
// create some consumers
try (ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory csf = createSessionFactory(locator);) {
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator)) {
ClientSessionImpl session1 = (ClientSessionImpl) csf.createSession();
Thread.sleep(500);
@ -4585,7 +4593,8 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
}
// create some consumers
try (ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory csf = createSessionFactory(locator);) {
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator)) {
ClientSession session1 = csf.createSession();
ClientSession session2 = csf.createSession();
@ -4645,7 +4654,8 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
}
// create some consumers
try (ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory csf = createSessionFactory(locator);) {
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator)) {
ClientSession session1 = csf.createSession();
ClientSession session2 = csf.createSession();
@ -4705,7 +4715,8 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
}
// create some consumers
try (ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory csf = createSessionFactory(locator);) {
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator)) {
ClientSession session1 = csf.createSession();
@ -4751,7 +4762,8 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
}
// create some consumers
try (ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory csf = createSessionFactory(locator);) {
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator)) {
ClientSession session1 = csf.createSession();
@ -4807,7 +4819,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
server.createQueue(new QueueConfiguration(queueName).setAddress(queueName).setRoutingType(RoutingType.ANYCAST).setDurable(false));
}
// create some producers
try (Connection conn = connectionFactory.createConnection();) {
try (Connection conn = connectionFactory.createConnection()) {
Session session1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
@ -4886,7 +4898,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
ActiveMQConnectionFactory connectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
// create some producers
try (Connection conn = connectionFactory.createConnection();) {
try (Connection conn = connectionFactory.createConnection()) {
Session session1 = conn.createSession();
Session session2 = conn.createSession();
@ -4983,7 +4995,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
});
ActiveMQConnectionFactory connectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
// create some producers
try (Connection conn = connectionFactory.createConnection();) {
try (Connection conn = connectionFactory.createConnection()) {
Session session1 = conn.createSession();
@ -5060,7 +5072,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
ActiveMQConnectionFactory connectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
// create some producers
try (Connection conn = connectionFactory.createConnection();) {
try (Connection conn = connectionFactory.createConnection()) {
Session session1 = conn.createSession();
@ -5138,7 +5150,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
server.createQueue(new QueueConfiguration(queueName).setAddress(queueName).setRoutingType(RoutingType.ANYCAST).setDurable(false));
}
// create some producers
try (Connection conn = connectionFactory.createConnection();) {
try (Connection conn = connectionFactory.createConnection()) {
Session session1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
@ -5234,7 +5246,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
server.createQueue(new QueueConfiguration(queueName3).setAddress(queueName3).setRoutingType(RoutingType.ANYCAST).setDurable(false));
}
// create some producers
try (Connection conn = connectionFactory.createConnection();) {
try (Connection conn = connectionFactory.createConnection()) {
Session session1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
@ -5307,7 +5319,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
server.addAddressInfo(new AddressInfo(""));
try (Connection conn = connectionFactory.createConnection();) {
try (Connection conn = connectionFactory.createConnection()) {
conn.setClientID("clientID");
Session session1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session session2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
@ -5377,7 +5389,8 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
}
// create some consumers
try (ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory csf = createSessionFactory(locator);) {
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator)) {
ClientSession session1 = csf.createSession();
ClientSession session2 = csf.createSession();
@ -5461,7 +5474,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
int numMessages = 10;
try (Connection connection = connectionFactory.createConnection();) {
try (Connection connection = connectionFactory.createConnection()) {
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(session.createQueue(myQueue));
for (int i = 0; i < numMessages; i++) {
@ -5511,7 +5524,8 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
// create some consumers
try (ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory csf = createSessionFactory(locator);) {
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator)) {
ClientSession session1 = csf.createSession();
@ -5564,9 +5578,9 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
int numMessages = 10;
// create some consumers
try (ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory csf = createSessionFactory(locator);) {
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator)) {
ClientSession session1 = csf.createSession();
@ -5614,7 +5628,9 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
assertEquals("Memory Usage before adding messages", 0, serverControl.getAddressMemoryUsage());
assertEquals("MemoryUsagePercentage", 0, serverControl.getAddressMemoryUsagePercentage());
try (ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory csf = createSessionFactory(locator); ClientSession session = csf.createSession()) {
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator);
ClientSession session = csf.createSession()) {
if (legacyCreateQueue) {
session.createQueue(name1, RoutingType.ANYCAST, name1);
} else {
@ -5650,7 +5666,9 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
assertEquals("Memory Usage before adding messages", 0, serverControl.getAddressMemoryUsage());
assertEquals("MemoryUsagePercentage", 0, serverControl.getAddressMemoryUsagePercentage());
try (ServerLocator locator = createInVMNonHALocator(); ClientSessionFactory csf = createSessionFactory(locator); ClientSession session = csf.createSession()) {
try (ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator);
ClientSession session = csf.createSession()) {
if (legacyCreateQueue) {
session.createQueue(name1, RoutingType.ANYCAST, name1);
session.createQueue(name2, RoutingType.ANYCAST, name2);

View File

@ -1595,7 +1595,9 @@ public class QueueControlTest extends ManagementTestBase {
for (int i = 0; i < THREAD_COUNT; i++) {
producerExecutor.submit(() -> {
try (ClientSessionFactory sf = locator.createSessionFactory(); ClientSession session = sf.createSession(false, true, false); ClientProducer producer = session.createProducer(address)) {
try (ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(false, true, false);
ClientProducer producer = session.createProducer(address)) {
for (int j = 0; j < MSG_COUNT; j++) {
producer.send(session.createMessage(false));
Thread.sleep(5);
@ -1609,7 +1611,9 @@ public class QueueControlTest extends ManagementTestBase {
for (int i = 0; i < THREAD_COUNT; i++) {
consumerExecutor.submit(() -> {
try (ClientSessionFactory sf = locator.createSessionFactory(); ClientSession session = sf.createSession(false, true, false); ClientConsumer consumer = session.createConsumer(queue)) {
try (ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(false, true, false);
ClientConsumer consumer = session.createConsumer(queue)) {
session.start();
for (int j = 0; j < MSG_COUNT; j++) {
ClientMessage message = consumer.receive(500);

View File

@ -160,7 +160,9 @@ public class PageCounterRebuildTest extends ActiveMQTestBase {
try {
startFlag.await(10, TimeUnit.SECONDS);
ConnectionFactory factory = CFUtil.createConnectionFactory("core", "tcp://localhost:61616");
try (Connection connection = factory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Session txSession = connection.createSession(true, Session.AUTO_ACKNOWLEDGE)) {
try (Connection connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session txSession = connection.createSession(true, Session.AUTO_ACKNOWLEDGE)) {
logger.info("sending thread {}", threadNumber);
@ -194,7 +196,8 @@ public class PageCounterRebuildTest extends ActiveMQTestBase {
Wait.assertEquals(numberOfMessages, serverQueue::getMessageCount);
ConnectionFactory factory = CFUtil.createConnectionFactory("core", "tcp://localhost:61616");
try (Connection connection = factory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);) {
try (Connection connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
MessageConsumer consumer = session.createConsumer(session.createQueue(queueName + "::" + queueName));
connection.start();
for (int i = 0; i < CONSUME_MESSAGES; i++) {
@ -257,7 +260,8 @@ public class PageCounterRebuildTest extends ActiveMQTestBase {
logger.info("Consuming messages");
factory = CFUtil.createConnectionFactory("core", "tcp://localhost:61616");
try (Connection connection = factory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);) {
try (Connection connection = factory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)) {
MessageConsumer consumer = session.createConsumer(session.createQueue(queueName + "::" + queueName));
connection.start();
for (int i = 0; i < numberOfMessages - CONSUME_MESSAGES; i++) {

View File

@ -108,7 +108,8 @@ public class FederationBrokerPluginTest extends FederatedTestBase {
private void testFederationStreamConsumerAddress(String address) throws Exception {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection1.start();
connection0.start();
@ -166,7 +167,8 @@ public class FederationBrokerPluginTest extends FederatedTestBase {
private void testFederationStreamConsumerQueue(String queueName) throws Exception {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection0.start();
connection1.start();
@ -214,7 +216,8 @@ public class FederationBrokerPluginTest extends FederatedTestBase {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection1.start();
connection0.start();
@ -262,7 +265,8 @@ public class FederationBrokerPluginTest extends FederatedTestBase {
ConnectionFactory cf1 = getCF(1);
ConnectionFactory cf0 = getCF(0);
try (Connection connection1 = cf1.createConnection(); Connection connection0 = cf0.createConnection()) {
try (Connection connection1 = cf1.createConnection();
Connection connection0 = cf0.createConnection()) {
connection0.start();
connection1.start();

View File

@ -845,7 +845,8 @@ public class DNSSwitchTest extends SmokeTestBase {
Wait.assertTrue(() -> !liveControl.isReplicaSync());
logger.debug("Waiting enough to let live spread its topology around");
try (ActiveMQConnectionFactory firstCf = new ActiveMQConnectionFactory("tcp://FIRST:61616?ha=false"); Connection ignored = firstCf.createConnection()) {
try (ActiveMQConnectionFactory firstCf = new ActiveMQConnectionFactory("tcp://FIRST:61616?ha=false");
Connection ignored = firstCf.createConnection()) {
waitForTopology(firstCf.getServerLocator().getTopology(), 60_000, 1, 1);
final Topology topology = firstCf.getServerLocator().getTopology();
final TopologyMemberImpl member = topology.getMember(liveControl.getNodeID());
@ -862,7 +863,8 @@ public class DNSSwitchTest extends SmokeTestBase {
Assert.assertEquals("SECOND", backup.getParams().get("host"));
Assert.assertEquals("61716", backup.getParams().get("port"));
}
try (ActiveMQConnectionFactory secondCf = new ActiveMQConnectionFactory("tcp://SECOND:61716?ha=false"); Connection ignored = secondCf.createConnection()) {
try (ActiveMQConnectionFactory secondCf = new ActiveMQConnectionFactory("tcp://SECOND:61716?ha=false");
Connection ignored = secondCf.createConnection()) {
logger.debug("Waiting until second broker topology has just a single live node");
waitForTopology(secondCf.getServerLocator().getTopology(), 60_000, 1, 0);
final Topology topology = secondCf.getServerLocator().getTopology();

View File

@ -137,7 +137,8 @@ public class CompareUpgradeTest {
if (f.getName().endsWith(".exe")) {
Assert.assertArrayEquals(f.getName() + " is different after upgrade", Files.readAllBytes(f.toPath()), Files.readAllBytes(upgradeFile.toPath()));
} else {
try (Stream<String> expectedStream = Files.lines(f.toPath()); Stream<String> upgradeStream = Files.lines(upgradeFile.toPath())) {
try (Stream<String> expectedStream = Files.lines(f.toPath());
Stream<String> upgradeStream = Files.lines(upgradeFile.toPath())) {
Iterator<String> expectedIterator = expectedStream.iterator();
Iterator<String> upgradeIterator = upgradeStream.iterator();