Skip to content

Commit

Permalink
[WFLY-8427] compare destroyedCount with real value after pool has bee…
Browse files Browse the repository at this point in the history
…n filled, not with 0

https://issues.jboss.org/browse/JBJCA-1344 describes how it can happen that initial destroyedCount isn't 0
  • Loading branch information
simkam committed Apr 18, 2017
1 parent ef9abb5 commit 821e642
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
Expand Up @@ -144,19 +144,22 @@ public void testNonDefaultDecrementerAndIncrementer() throws Exception {
Connection[] connections = new Connection[4];
connections[0] = ds.getConnection();

// wait until IJ PoolFiller and CapacityFiller fill pool with expected number of connections
waitForPool(2000);
// wait until IJ PoolFiller and CapacityFiller fill pool with expected number of connections,
// also remember initial destroyedCount, IJ fills pool with two threads (CapacityFiller and PoolFiller)
// and it can result in one connection created and immediately destroyed because pool has been already filled
// by other thread, for details see https://issues.jboss.org/browse/JBJCA-1344
int initialDestroyedCount = waitForPool(2000);

checkStatistics(4, 1, 5, 0);
checkStatistics(4, 1, 5, initialDestroyedCount);

connections[1] = ds.getConnection();
checkStatistics(3, 2, 5, 0);
checkStatistics(3, 2, 5, initialDestroyedCount);

connections[2] = ds.getConnection();
checkStatistics(2, 3, 5, 0);
checkStatistics(2, 3, 5, initialDestroyedCount);

connections[3] = ds.getConnection();
checkStatistics(1, 4, 5, 0);
checkStatistics(1, 4, 5, initialDestroyedCount);

for (int i = 0; i < 4; i++) {
Connection c = connections[i];
Expand All @@ -167,7 +170,7 @@ public void testNonDefaultDecrementerAndIncrementer() throws Exception {
ManagedConnectionPool mcp = JcaTestsUtil.extractManagedConnectionPool(wsds);
JcaTestsUtil.callRemoveIdleConnections(mcp);

checkStatistics(5, 0, 2, 3);
checkStatistics(5, 0, 2, initialDestroyedCount + 3);
}

private void checkStatistics(int expectedAvailableCount, int expectedInUseCount,
Expand All @@ -188,7 +191,7 @@ private int readStatisticsAttribute(final String attributeName) throws Exception
return readAttribute(statisticsAddress, attributeName).asInt();
}

private void waitForPool(final int timeout) throws Exception {
private int waitForPool(final int timeout) throws Exception {
long waitTimeout = TimeoutUtil.adjust(timeout);
long sleep = 50L;
while (true) {
Expand All @@ -197,7 +200,7 @@ private void waitForPool(final int timeout) throws Exception {
int activeCount = readStatisticsAttribute("ActiveCount");

if (availableCount == 4 && inUseCount == 1 && activeCount == 5)
return;
return readStatisticsAttribute("DestroyedCount");
TimeUnit.MILLISECONDS.sleep(sleep);

waitTimeout -= sleep;
Expand Down
Expand Up @@ -163,19 +163,22 @@ public void testNonDefaultDecrementerAndIncrementer() throws Exception {
LazyConnection[] connections = new LazyConnection[4];
connections[0] = lcf.getConnection();

// wait until IJ PoolFiller and CapacityFiller fill pool with expected number of connections
waitForPool(2000);
// wait until IJ PoolFiller and CapacityFiller fill pool with expected number of connections,
// also remember initial destroyedCount, IJ fills pool with two threads (CapacityFiller and PoolFiller)
// and it can result in one connection created and immediately destroyed because pool has been already filled
// by other thread, for details see https://issues.jboss.org/browse/JBJCA-1344
int initialDestroyedCount = waitForPool(2000);

checkStatistics(4, 1, 5, 0);
checkStatistics(4, 1, 5, initialDestroyedCount);

connections[1] = lcf.getConnection();
checkStatistics(3, 2, 5, 0);
checkStatistics(3, 2, 5, initialDestroyedCount);

connections[2] = lcf.getConnection();
checkStatistics(2, 3, 5, 0);
checkStatistics(2, 3, 5, initialDestroyedCount);

connections[3] = lcf.getConnection();
checkStatistics(1, 4, 5, 0);
checkStatistics(1, 4, 5, initialDestroyedCount);

for (int i = 0; i < 4; i++) {
LazyConnection c = connections[i];
Expand All @@ -185,7 +188,7 @@ public void testNonDefaultDecrementerAndIncrementer() throws Exception {
ManagedConnectionPool mcp = JcaTestsUtil.extractManagedConnectionPool(lcf);
JcaTestsUtil.callRemoveIdleConnections(mcp);

checkStatistics(5, 0, 2, 3);
checkStatistics(5, 0, 2, initialDestroyedCount + 3);
}

private void checkStatistics(int expectedAvailableCount, int expectedInUseCount,
Expand All @@ -205,7 +208,7 @@ private int readStatisticsAttribute(final String attributeName) throws Exception
return readAttribute(STATISTICS_ADDRESS, attributeName).asInt();
}

private void waitForPool(final int timeout) throws Exception {
private int waitForPool(final int timeout) throws Exception {
long waitTimeout = TimeoutUtil.adjust(timeout);
long sleep = 50L;
while (true) {
Expand All @@ -214,7 +217,7 @@ private void waitForPool(final int timeout) throws Exception {
int activeCount = readStatisticsAttribute("ActiveCount");

if (availableCount == 4 && inUseCount == 1 && activeCount == 5)
return;
return readStatisticsAttribute("DestroyedCount");
TimeUnit.MILLISECONDS.sleep(sleep);

waitTimeout -= sleep;
Expand Down
Expand Up @@ -25,8 +25,6 @@

import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
Expand All @@ -51,9 +49,4 @@ static class DatasourceServerSetupTask extends AbstractDatasourceCapacityPolicie
}
}

@Test
@Ignore("WFLY-8427")
public void testNonDefaultDecrementerAndIncrementer() throws Exception {

}
}

0 comments on commit 821e642

Please sign in to comment.