This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new bc3c072 Fix SpotBugs warnings
bc3c072 is described below
commit bc3c0724a558ba2014b91e452779f1f388f3fe7b
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Feb 28 16:49:42 2019 +0000
Fix SpotBugs warnings
int -> AtomicInteger to address atomicity issues
Refactoring to address Serialization issues
---
.../catalina/nonblocking/TestNonBlockingAPI.java | 49 ++++++++++++----------
1 file changed, 27 insertions(+), 22 deletions(-)
diff --git a/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java
b/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java
index 60d894a..8725623 100644
--- a/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java
+++ b/test/org/apache/catalina/nonblocking/TestNonBlockingAPI.java
@@ -32,6 +32,7 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.net.SocketFactory;
import javax.servlet.AsyncContext;
@@ -57,11 +58,15 @@ import org.apache.catalina.startup.TesterServlet;
import org.apache.catalina.startup.Tomcat;
import org.apache.catalina.startup.TomcatBaseTest;
import org.apache.catalina.valves.TesterAccessLogValve;
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.buf.ByteChunk;
import org.apache.tomcat.util.net.ContainerThreadMarker;
public class TestNonBlockingAPI extends TomcatBaseTest {
+ private static final Log log = LogFactory.getLog(TestNonBlockingAPI.class);
+
private static final int CHUNK_SIZE = 1024 * 1024;
private static final int WRITE_SIZE = CHUNK_SIZE * 10;
private static final byte[] DATA = new byte[WRITE_SIZE];
@@ -125,8 +130,8 @@ public class TestNonBlockingAPI extends TomcatBaseTest {
if (async) {
Assert.assertEquals(2000000 * 8, servlet.listener.body.length());
TestAsyncReadListener listener = (TestAsyncReadListener)
servlet.listener;
- Assert.assertTrue(Math.abs(listener.containerThreadCount -
listener.notReadyCount) <= 1);
- Assert.assertEquals(listener.isReadyCount,
listener.nonContainerThreadCount);
+ Assert.assertTrue(Math.abs(listener.containerThreadCount.get() -
listener.notReadyCount.get()) <= 1);
+ Assert.assertEquals(listener.isReadyCount.get(),
listener.nonContainerThreadCount.get());
} else {
Assert.assertEquals(5 * 8, servlet.listener.body.length());
}
@@ -470,11 +475,11 @@ public class TestNonBlockingAPI extends TomcatBaseTest {
}
@WebServlet(asyncSupported = true)
- public class NBReadServlet extends TesterServlet {
+ public static class NBReadServlet extends TesterServlet {
private static final long serialVersionUID = 1L;
private final boolean async;
private final boolean ignoreIsReady;
- TestReadListener listener;
+ transient TestReadListener listener;
public NBReadServlet(boolean ignoreIsReady, boolean async) {
this.async = async;
@@ -524,10 +529,10 @@ public class TestNonBlockingAPI extends TomcatBaseTest {
}
@WebServlet(asyncSupported = true)
- public class NBWriteServlet extends TesterServlet {
+ public static class NBWriteServlet extends TesterServlet {
private static final long serialVersionUID = 1L;
- public volatile TestWriteListener wlistener;
- public volatile TestReadListener rlistener;
+ public transient volatile TestWriteListener wlistener;
+ public transient volatile TestReadListener rlistener;
@Override
protected void service(HttpServletRequest req, HttpServletResponse
resp) throws ServletException, IOException {
@@ -570,9 +575,9 @@ public class TestNonBlockingAPI extends TomcatBaseTest {
}
@WebServlet(asyncSupported = true)
- public class NBReadWriteServlet extends TesterServlet {
+ public static class NBReadWriteServlet extends TesterServlet {
private static final long serialVersionUID = 1L;
- public volatile TestReadWriteListener rwlistener;
+ public transient volatile TestReadWriteListener rwlistener;
@Override
protected void service(HttpServletRequest req, HttpServletResponse
resp) throws ServletException, IOException {
@@ -587,7 +592,7 @@ public class TestNonBlockingAPI extends TomcatBaseTest {
}
}
- private class TestReadListener implements ReadListener {
+ private static class TestReadListener implements ReadListener {
protected final AsyncContext ctx;
protected final boolean usingNonBlockingWrite;
protected final boolean ignoreIsReady;
@@ -649,12 +654,12 @@ public class TestNonBlockingAPI extends TomcatBaseTest {
}
}
- private class TestAsyncReadListener extends TestReadListener {
+ private static class TestAsyncReadListener extends TestReadListener {
- volatile int isReadyCount = 0;
- volatile int notReadyCount = 0;
- volatile int containerThreadCount = 0;
- volatile int nonContainerThreadCount = 0;
+ AtomicInteger isReadyCount = new AtomicInteger(0);
+ AtomicInteger notReadyCount = new AtomicInteger(0);
+ AtomicInteger containerThreadCount = new AtomicInteger(0);
+ AtomicInteger nonContainerThreadCount = new AtomicInteger(0);
public TestAsyncReadListener(AsyncContext ctx,
boolean usingNonBlockingWrite, boolean ignoreIsReady) {
@@ -664,9 +669,9 @@ public class TestNonBlockingAPI extends TomcatBaseTest {
@Override
public void onDataAvailable() throws IOException {
if (ContainerThreadMarker.isContainerThread()) {
- containerThreadCount++;
+ containerThreadCount.incrementAndGet();
} else {
- nonContainerThreadCount++;
+ nonContainerThreadCount.incrementAndGet();
}
new Thread() {
@Override
@@ -685,9 +690,9 @@ public class TestNonBlockingAPI extends TomcatBaseTest {
}
boolean isReady = ignoreIsReady || in.isReady();
if (isReady) {
- isReadyCount++;
+ isReadyCount.incrementAndGet();
} else {
- notReadyCount++;
+ notReadyCount.incrementAndGet();
}
if (isReady) {
onDataAvailable();
@@ -716,7 +721,7 @@ public class TestNonBlockingAPI extends TomcatBaseTest {
}
}
- private class TestWriteListener implements WriteListener {
+ private static class TestWriteListener implements WriteListener {
AsyncContext ctx;
int written = 0;
public volatile boolean onErrorInvoked = false;
@@ -760,7 +765,7 @@ public class TestNonBlockingAPI extends TomcatBaseTest {
}
- private class TestReadWriteListener implements ReadListener {
+ private static class TestReadWriteListener implements ReadListener {
AsyncContext ctx;
private final StringBuilder body = new StringBuilder();
@@ -1030,7 +1035,7 @@ public class TestNonBlockingAPI extends TomcatBaseTest {
@WebServlet(asyncSupported = true)
- private final class NBReadWithDispatchServlet extends TesterServlet {
+ private static final class NBReadWithDispatchServlet extends TesterServlet
{
private static final long serialVersionUID = 1L;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]