You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2022/06/03 20:24:36 UTC
[ws-axiom] branch master updated: Make use of lambdas
This is an automated email from the ASF dual-hosted git repository.
veithen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git
The following commit(s) were added to refs/heads/master by this push:
new 03ebfdce0 Make use of lambdas
03ebfdce0 is described below
commit 03ebfdce06a4d62b4d1b17ce19117500ae033347
Author: Andreas Veithen <an...@gmail.com>
AuthorDate: Fri Jun 3 20:21:16 2022 +0000
Make use of lambdas
---
.../apache/axiom/attachments/AttachmentsTest.java | 19 +++---
.../org/apache/axiom/util/UIDGeneratorTest.java | 32 ++++-----
.../soap12/envelope/TestMTOMForwardStreaming.java | 76 ++++++++++------------
.../testutils/concurrent/ConcurrentTestUtils.java | 31 ++++-----
4 files changed, 70 insertions(+), 88 deletions(-)
diff --git a/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java b/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
index 8e54d5c7d..016e12f46 100644
--- a/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
+++ b/axiom-api/src/test/java/org/apache/axiom/attachments/AttachmentsTest.java
@@ -618,21 +618,18 @@ public class AttachmentsTest extends AbstractTestCase {
// We use a pipe (with a producer running in a separate thread) because obviously we can't
// store the multipart in memory.
- final PipedOutputStream pipeOut = new PipedOutputStream();
+ PipedOutputStream pipeOut = new PipedOutputStream();
PipedInputStream pipeIn = new PipedInputStream(pipeOut);
- Thread producerThread = new Thread(new Runnable() {
- @Override
- public void run() {
+ Thread producerThread = new Thread(() -> {
+ try {
try {
- try {
- mp.writeTo(pipeOut);
- } finally {
- pipeOut.close();
- }
- } catch (Exception ex) {
- ex.printStackTrace();
+ mp.writeTo(pipeOut);
+ } finally {
+ pipeOut.close();
}
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
});
producerThread.start();
diff --git a/axiom-api/src/test/java/org/apache/axiom/util/UIDGeneratorTest.java b/axiom-api/src/test/java/org/apache/axiom/util/UIDGeneratorTest.java
index 5603f5ded..9d1bf82f0 100644
--- a/axiom-api/src/test/java/org/apache/axiom/util/UIDGeneratorTest.java
+++ b/axiom-api/src/test/java/org/apache/axiom/util/UIDGeneratorTest.java
@@ -47,19 +47,16 @@ public class UIDGeneratorTest extends TestCase {
}
public void testGenerateUIDThreadSafety() {
- final Set<String> generatedIds = Collections.synchronizedSet(new HashSet<String>());
- final AtomicInteger errorCount = new AtomicInteger(0);
+ Set<String> generatedIds = Collections.synchronizedSet(new HashSet<String>());
+ AtomicInteger errorCount = new AtomicInteger(0);
Thread[] threads = new Thread[100];
for (int i = 0; i < threads.length; i++) {
- threads[i] = new Thread(new Runnable() {
- @Override
- public void run() {
- for (int i=0; i<1000; i++) {
- String id = UIDGenerator.generateUID();
- if (!generatedIds.add(id)) {
- System.out.println("ERROR - Same UID has been generated before. UID: " + id);
- errorCount.incrementAndGet();
- }
+ threads[i] = new Thread(() -> {
+ for (int j=0; j<1000; j++) {
+ String id = UIDGenerator.generateUID();
+ if (!generatedIds.add(id)) {
+ System.out.println("ERROR - Same UID has been generated before. UID: " + id);
+ errorCount.incrementAndGet();
}
}
});
@@ -79,15 +76,12 @@ public class UIDGeneratorTest extends TestCase {
public void testGenerateURNString() {
Thread[] threads = new Thread[100];
- final String[][] urns = new String[threads.length][1000];
+ String[][] urns = new String[threads.length][1000];
for (int i = 0; i < threads.length; i++) {
- final String[] threadURNs = urns[i];
- threads[i] = new Thread(new Runnable() {
- @Override
- public void run() {
- for (int i=0; i<threadURNs.length; i++) {
- threadURNs[i] = UIDGenerator.generateURNString();
- }
+ String[] threadURNs = urns[i];
+ threads[i] = new Thread(() -> {
+ for (int j=0; j<threadURNs.length; j++) {
+ threadURNs[j] = UIDGenerator.generateURNString();
}
});
threads[i].start();
diff --git a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestMTOMForwardStreaming.java b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestMTOMForwardStreaming.java
index 09ce85b48..355a3a6b9 100644
--- a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestMTOMForwardStreaming.java
+++ b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap12/envelope/TestMTOMForwardStreaming.java
@@ -71,68 +71,62 @@ public class TestMTOMForwardStreaming extends AxiomTestCase {
OMElement orgData2 = factory.createOMElement("data", null, orgBodyElement);
orgData2.addChild(factory.createOMText(new DataHandler(ds2), true));
- final OMOutputFormat format = new OMOutputFormat();
+ OMOutputFormat format = new OMOutputFormat();
format.setDoOptimize(true);
format.setSOAP11(false);
- final String contentType = format.getContentType();
+ String contentType = format.getContentType();
- final PipedOutputStream pipe1Out = new PipedOutputStream();
- final PipedInputStream pipe1In = new PipedInputStream(pipe1Out);
+ PipedOutputStream pipe1Out = new PipedOutputStream();
+ PipedInputStream pipe1In = new PipedInputStream(pipe1Out);
// Create the producer thread (simulating the client sending the MTOM message)
Thread producerThread =
new Thread(
- new Runnable() {
- @Override
- public void run() {
+ () -> {
+ try {
try {
- try {
- orgEnvelope.serialize(pipe1Out, format);
- } finally {
- pipe1Out.close();
- }
- } catch (Exception ex) {
- ex.printStackTrace();
+ orgEnvelope.serialize(pipe1Out, format);
+ } finally {
+ pipe1Out.close();
}
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
});
producerThread.start();
- final PipedOutputStream pipe2Out = new PipedOutputStream();
+ PipedOutputStream pipe2Out = new PipedOutputStream();
PipedInputStream pipe2In = new PipedInputStream(pipe2Out);
// Create the forwarder thread (simulating the mediation engine that forwards the message)
Thread forwarderThread =
new Thread(
- new Runnable() {
- @Override
- public void run() {
+ () -> {
+ try {
try {
- try {
- MultipartBody mb =
- MultipartBody.builder()
- .setInputStream(pipe1In)
- .setContentType(contentType)
- .build();
- SOAPEnvelope envelope =
- OMXMLBuilderFactory.createSOAPModelBuilder(
- metaFactory, mb)
- .getSOAPEnvelope();
- // The code path executed by serializeAndConsume is
- // significantly different if
- // the element is built. Therefore we need two different
- // test executions.
- if (buildSOAPPart) {
- envelope.build();
- }
- // Usage of serializeAndConsume should enable streaming
- envelope.serializeAndConsume(pipe2Out, format);
- } finally {
- pipe2Out.close();
+ MultipartBody mb =
+ MultipartBody.builder()
+ .setInputStream(pipe1In)
+ .setContentType(contentType)
+ .build();
+ SOAPEnvelope envelope =
+ OMXMLBuilderFactory.createSOAPModelBuilder(
+ metaFactory, mb)
+ .getSOAPEnvelope();
+ // The code path executed by serializeAndConsume is
+ // significantly different if
+ // the element is built. Therefore we need two different
+ // test executions.
+ if (buildSOAPPart) {
+ envelope.build();
}
- } catch (Exception ex) {
- ex.printStackTrace();
+ // Usage of serializeAndConsume should enable streaming
+ envelope.serializeAndConsume(pipe2Out, format);
+ } finally {
+ pipe2Out.close();
}
+ } catch (Exception ex) {
+ ex.printStackTrace();
}
});
forwarderThread.start();
diff --git a/testing/testutils/src/main/java/org/apache/axiom/testutils/concurrent/ConcurrentTestUtils.java b/testing/testutils/src/main/java/org/apache/axiom/testutils/concurrent/ConcurrentTestUtils.java
index 98771a280..a360a1557 100644
--- a/testing/testutils/src/main/java/org/apache/axiom/testutils/concurrent/ConcurrentTestUtils.java
+++ b/testing/testutils/src/main/java/org/apache/axiom/testutils/concurrent/ConcurrentTestUtils.java
@@ -24,26 +24,23 @@ import java.util.List;
public class ConcurrentTestUtils {
- public static void testThreadSafety(final Action action) throws Throwable {
+ public static void testThreadSafety(Action action) throws Throwable {
int threadCount = 10;
- final List<Throwable> results = new ArrayList<>(threadCount);
+ List<Throwable> results = new ArrayList<>(threadCount);
for (int i=0; i<threadCount; i++) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- Throwable result;
- try {
- for (int i=0; i<1000; i++) {
- action.execute();
- }
- result = null;
- } catch (Throwable ex) {
- result = ex;
- }
- synchronized (results) {
- results.add(result);
- results.notifyAll();
+ new Thread(() -> {
+ Throwable result;
+ try {
+ for (int j=0; j<1000; j++) {
+ action.execute();
}
+ result = null;
+ } catch (Throwable ex) {
+ result = ex;
+ }
+ synchronized (results) {
+ results.add(result);
+ results.notifyAll();
}
}).start();
}