Skip to content

Commit

Permalink
[WFLY-15366] split and simplify DataSourceMultipleConnStatsTestCase
Browse files Browse the repository at this point in the history
https://issues.redhat.com/browse/WFLY-15366

The test case was unstable because of missing `ExecutorService.awaitTermination` in the first test so there could still be active requests that could interfere with the second test. Also tests in this test case tested different scenarios with different configurations so I split them into two test cases with two setup tasks. I also removed the asynchronous calls to the servlet. The second test doesn't need an asynchronous call, and the first test only need to add a connection request to queue.
  • Loading branch information
simkam committed Jun 13, 2024
1 parent 1b758e7 commit 88eddc8
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 296 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.test.integration.jca.statistics;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import javax.sql.DataSource;

import jakarta.annotation.Resource;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.client.helpers.Operations;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.dmr.ModelNode;

public abstract class AbstractDataSourcePoolStatisticsTestCase {

private Set<Connection> connections = new CopyOnWriteArraySet<>();

@ArquillianResource
protected ManagementClient managementClient;

@Resource(lookup = "java:jboss/datasources/ExampleDS")
private DataSource dataSource;

// /subsystem=datasources/data-source=ExampleDS/statistics=pool:read-attribute(name=AvailableCount)
protected int readStatisticsAttribute(String attributeName) throws Exception {
PathAddress statisticsPathAddress = PathAddress.parseCLIStyleAddress("/subsystem=datasources/data-source=ExampleDS/statistics=pool");
ModelNode readAttributeOperation = Util.getReadAttributeOperation(statisticsPathAddress, attributeName);

ModelNode result = managementClient.getControllerClient().execute(readAttributeOperation);
assertThat("Failed to read statistics: " + result, Operations.isSuccessfulOutcome(result), is(true));
return Operations.readResult(result).asInt();
}

// /subsystem=datasources/data-source=ExampleDS/statistics=pool/clear-statistics
protected void clearStatistics() throws Exception {
PathAddress statisticsPathAddress = PathAddress.parseCLIStyleAddress("/subsystem=datasources/data-source=ExampleDS/statistics=pool/");
ModelNode operation = Util.createOperation("clear-statistics", statisticsPathAddress);
ModelNode result = managementClient.getControllerClient().execute(operation);
assertThat("Failed to configure connection pool: " + result, Operations.isSuccessfulOutcome(result), is(true));
}

protected void allocateConnection() throws SQLException {
connections.add(dataSource.getConnection());
}

protected void clearConnections() {
connections.forEach(connection -> {
try {
connection.close();
} catch (SQLException sqle) {
throw new RuntimeException(sqle);
}
});
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 88eddc8

Please sign in to comment.