You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2024/01/03 11:29:48 UTC
(tomcat) 05/12: Refactor test that requires large heap into a separate category
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit b4634a97233ffbfc0ac4e2936e99ba7740f23e2c
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jan 3 09:20:32 2024 +0000
Refactor test that requires large heap into a separate category
Tests requiring large heaps are still disabled by default but:
- do not appear in the list of skipped tests
- can be enabled with a build property rather than a code change
---
BUILDING.txt | 21 ++-
build.xml | 2 +
.../EncryptionInterceptorBaseTest.java | 185 +++++++++++++++++++++
.../group/interceptors/TestEncryptInterceptor.java | 159 +-----------------
.../TestEncryptInterceptorLargeHeap.java | 47 ++++++
5 files changed, 249 insertions(+), 165 deletions(-)
diff --git a/BUILDING.txt b/BUILDING.txt
index 799b579ba8..0acef652a1 100644
--- a/BUILDING.txt
+++ b/BUILDING.txt
@@ -488,8 +488,8 @@ NOTE: Cobertura is licensed under GPL v2 with parts of it being under
output/coverage
- 7. The performance tests are written to run reasonably powerful machines (such
- as a developer may use day to day) assuming no other resource hungry
+ 7. The performance tests are written to run on reasonably powerful machines
+ (such as a developer may use day to day) assuming no other resource hungry
processes are running.
These assumptions are not always true (e.g. on CI systems running in a
@@ -498,19 +498,26 @@ NOTE: Cobertura is licensed under GPL v2 with parts of it being under
test.excludePerformance=true
- 8. Some tests include checks that the access log valve entries are as expected.
+ 8. Some tests are require large heaps (e.g. 8GB). The CI systems used by the
+ project either cannot support heaps of this size or do not support them by
+ default. These tests are therefore disabled by default and may be enabled by
+ using the following property:
+
+ test.includeLargeHeap=true
+
+ 9. Some tests include checks that the access log valve entries are as expected.
These checks include timings. On slower / loaded systems these checks will
often fail. The checks may be relaxed by using the following property:
test.relaxTiming=true
- 9. It is known that some platforms (e.g. OSX El Capitan) require IPv4 to
- be the default for the multicast tests to work. This is configured by
- the following property:
+ 10. It is known that some platforms (e.g. OSX El Capitan) require IPv4 to
+ be the default for the multicast tests to work. This is configured by
+ the following property:
java.net.preferIPv4Stack=true
- 10. By default the output of unit tests is sent to the console and can be
+ 11. By default the output of unit tests is sent to the console and can be
quite verbose. The output can be deactivated by setting the property:
test.verbose=false
diff --git a/build.xml b/build.xml
index 217f407067..806c47d4b9 100644
--- a/build.xml
+++ b/build.xml
@@ -2070,6 +2070,8 @@
<exclude name="**/*Performance.java" if="${test.excludePerformance}" />
<!-- Exclude tests that Gump can't compile -->
<exclude name="org/apache/tomcat/buildutil/**" />
+ <!-- Exclude tests that require large heaps -->
+ <exclude name="**/*LargeHeap.java" unless="${test.includeLargeHeap}" />
</fileset>
</batchtest>
</junit>
diff --git a/test/org/apache/catalina/tribes/group/interceptors/EncryptionInterceptorBaseTest.java b/test/org/apache/catalina/tribes/group/interceptors/EncryptionInterceptorBaseTest.java
new file mode 100644
index 0000000000..c3db40dc28
--- /dev/null
+++ b/test/org/apache/catalina/tribes/group/interceptors/EncryptionInterceptorBaseTest.java
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.catalina.tribes.group.interceptors;
+
+import java.io.File;
+import java.security.Security;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+
+import org.apache.catalina.tribes.ChannelException;
+import org.apache.catalina.tribes.ChannelInterceptor;
+import org.apache.catalina.tribes.ChannelMessage;
+import org.apache.catalina.tribes.Member;
+import org.apache.catalina.tribes.group.ChannelInterceptorBase;
+import org.apache.catalina.tribes.group.InterceptorPayload;
+import org.apache.catalina.tribes.io.ChannelData;
+import org.apache.catalina.tribes.io.XByteBuffer;
+
+public class EncryptionInterceptorBaseTest {
+
+ protected static final String MESSAGE_FILE = "message.bin";
+
+ protected static final String encryptionKey128 = "cafebabedeadbeefbeefcafecafebabe";
+ protected static final String encryptionKey192 = "cafebabedeadbeefbeefcafecafebabedeadbeefbeefcafe";
+ protected static final String encryptionKey256 = "cafebabedeadbeefcafebabedeadbeefcafebabedeadbeefcafebabedeadbeef";
+
+ protected EncryptInterceptor src;
+ protected EncryptInterceptor dest;
+
+
+ @BeforeClass
+ public static void setupClass() {
+ Security.setProperty("jdk.tls.disabledAlgorithms", "");
+ Security.setProperty("crypto.policy", "unlimited");
+ }
+
+
+ @AfterClass
+ public static void cleanup() {
+ File f = new File(MESSAGE_FILE);
+ if (f.isFile()) {
+ Assert.assertTrue(f.delete());
+ }
+ }
+
+
+ @Before
+ public void setup() {
+ src = new EncryptInterceptor();
+ src.setEncryptionKey(encryptionKey128);
+
+ dest = new EncryptInterceptor();
+ dest.setEncryptionKey(encryptionKey128);
+
+ src.setNext(new PipedInterceptor(dest));
+ dest.setPrevious(new ValueCaptureInterceptor());
+ }
+
+
+ /**
+ * Actually go through the interceptor's send/receive message methods.
+ *
+ * @param input The clear text message to sent
+ * @param src The interceptor to use to encrypt the message
+ * @param dest The interceptor to use to decrypt the message
+ *
+ * @return The clear text message received
+ */
+ protected static String roundTrip(String input, EncryptInterceptor src, EncryptInterceptor dest) throws Exception {
+ byte[] bytes = input.getBytes("UTF-8");
+
+ bytes = roundTrip(bytes, src, dest);
+
+ return new String(bytes, "UTF-8");
+ }
+
+
+ /**
+ * Actually go through the interceptor's send/receive message methods.
+ *
+ * @param input The clear text message to sent
+ * @param src The interceptor to use to encrypt the message
+ * @param dest The interceptor to use to decrypt the message
+ *
+ * @return The clear text message received
+ */
+ protected static byte[] roundTrip(byte[] input, EncryptInterceptor src, EncryptInterceptor dest) throws Exception {
+ ChannelData msg = new ChannelData(false);
+ msg.setMessage(new XByteBuffer(input, false));
+ src.sendMessage(null, msg, null);
+
+ return ((ValueCaptureInterceptor) dest.getPrevious()).getValue();
+ }
+
+
+ /**
+ * Interceptor that delivers directly to a destination.
+ */
+ protected static class PipedInterceptor extends ChannelInterceptorBase {
+ private ChannelInterceptor dest;
+
+ PipedInterceptor(ChannelInterceptor dest) {
+ if (null == dest) {
+ throw new IllegalArgumentException("Destination must not be null");
+ }
+
+ this.dest = dest;
+ }
+
+ @Override
+ public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)
+ throws ChannelException {
+ dest.messageReceived(msg);
+ }
+ }
+
+ /**
+ * Interceptor that simply captures the latest message sent to or received by it.
+ */
+ protected static class ValueCaptureInterceptor extends ChannelInterceptorBase {
+ private byte[] value;
+
+ @Override
+ public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)
+ throws ChannelException {
+ value = msg.getMessage().getBytes();
+ }
+
+ @Override
+ public void messageReceived(ChannelMessage msg) {
+ value = msg.getMessage().getBytes();
+ }
+
+ public byte[] getValue() {
+ return value;
+ }
+ }
+
+ /**
+ * Interceptor that simply captures all messages sent to or received by it.
+ */
+ protected static class ValuesCaptureInterceptor extends ChannelInterceptorBase {
+ private ArrayList<byte[]> messages = new ArrayList<>();
+
+ @Override
+ public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)
+ throws ChannelException {
+ synchronized (messages) {
+ messages.add(msg.getMessage().getBytes());
+ }
+ }
+
+ @Override
+ public void messageReceived(ChannelMessage msg) {
+ synchronized (messages) {
+ messages.add(msg.getMessage().getBytes());
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public Collection<byte[]> getValues() {
+ return (Collection<byte[]>) messages.clone();
+ }
+ }
+
+}
diff --git a/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptor.java b/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptor.java
index 2b211c425b..5815d274ff 100644
--- a/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptor.java
+++ b/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptor.java
@@ -19,8 +19,6 @@ package org.apache.catalina.tribes.group.interceptors;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
-import java.security.Security;
-import java.util.ArrayList;
import java.util.Collection;
import javax.crypto.Cipher;
@@ -29,23 +27,14 @@ import org.hamcrest.MatcherAssert;
import org.hamcrest.core.IsEqual;
import org.hamcrest.core.IsNot;
-import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Assume;
-import org.junit.Before;
-import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.apache.catalina.tribes.Channel;
import org.apache.catalina.tribes.ChannelException;
-import org.apache.catalina.tribes.ChannelInterceptor;
-import org.apache.catalina.tribes.ChannelMessage;
-import org.apache.catalina.tribes.Member;
-import org.apache.catalina.tribes.group.ChannelInterceptorBase;
-import org.apache.catalina.tribes.group.InterceptorPayload;
import org.apache.catalina.tribes.io.ChannelData;
import org.apache.catalina.tribes.io.XByteBuffer;
@@ -57,42 +46,7 @@ import org.apache.catalina.tribes.io.XByteBuffer;
* for readability for the tests and their outputs.
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class TestEncryptInterceptor {
- private static final String MESSAGE_FILE = "message.bin";
-
- private static final String encryptionKey128 = "cafebabedeadbeefbeefcafecafebabe";
- private static final String encryptionKey192 = "cafebabedeadbeefbeefcafecafebabedeadbeefbeefcafe";
- private static final String encryptionKey256 = "cafebabedeadbeefcafebabedeadbeefcafebabedeadbeefcafebabedeadbeef";
-
- EncryptInterceptor src;
- EncryptInterceptor dest;
-
-
- @BeforeClass
- public static void setupClass() {
- Security.setProperty("jdk.tls.disabledAlgorithms", "");
- Security.setProperty("crypto.policy", "unlimited");
- }
-
- @AfterClass
- public static void cleanup() {
- File f = new File(MESSAGE_FILE);
- if (f.isFile()) {
- Assert.assertTrue(f.delete());
- }
- }
-
- @Before
- public void setup() {
- src = new EncryptInterceptor();
- src.setEncryptionKey(encryptionKey128);
-
- dest = new EncryptInterceptor();
- dest.setEncryptionKey(encryptionKey128);
-
- src.setNext(new PipedInterceptor(dest));
- dest.setPrevious(new ValueCaptureInterceptor());
- }
+public class TestEncryptInterceptor extends EncryptionInterceptorBaseTest {
@Test
public void testBasic() throws Exception {
@@ -158,19 +112,6 @@ public class TestEncryptInterceptor {
roundTrip(bytes, src, dest));
}
- @Test
- @Ignore("Too big for default settings. Breaks Gump, Eclipse, ...")
- public void testHugePayload() throws Exception {
- src.start(Channel.SND_TX_SEQ);
- dest.start(Channel.SND_TX_SEQ);
-
- byte[] bytes = new byte[1024*1024*1024];
-
- Assert.assertArrayEquals("Huge payload roundtrip failed",
- bytes,
- roundTrip(bytes, src, dest));
- }
-
@Test
public void testCustomProvider() throws Exception {
src.setProviderName("SunJCE"); // Explicitly set the provider name
@@ -219,28 +160,6 @@ public class TestEncryptInterceptor {
roundTrip(testInput, src, dest));
}
- /**
- * Actually go through the interceptor's send/receive message methods.
- */
- private static String roundTrip(String input, EncryptInterceptor src, EncryptInterceptor dest) throws Exception {
- byte[] bytes = input.getBytes("UTF-8");
-
- bytes = roundTrip(bytes, src, dest);
-
- return new String(bytes, "UTF-8");
- }
-
- /**
- * Actually go through the interceptor's send/receive message methods.
- */
- private static byte[] roundTrip(byte[] input, EncryptInterceptor src, EncryptInterceptor dest) throws Exception {
- ChannelData msg = new ChannelData(false);
- msg.setMessage(new XByteBuffer(input, false));
- src.sendMessage(null, msg, null);
-
- return ((ValueCaptureInterceptor)dest.getPrevious()).getValue();
- }
-
@Test
public void testOFB() throws Exception {
src.setEncryptionAlgorithm("AES/OFB/PKCS5Padding");
@@ -455,80 +374,4 @@ public class TestEncryptInterceptor {
Assert.fail("EncryptionInterceptor should throw ChannelConfigException, not " + t.getClass().getName());
}
}
-
- /**
- * Interceptor that delivers directly to a destination.
- */
- private static class PipedInterceptor
- extends ChannelInterceptorBase
- {
- private ChannelInterceptor dest;
-
- PipedInterceptor(ChannelInterceptor dest) {
- if(null == dest) {
- throw new IllegalArgumentException("Destination must not be null");
- }
-
- this.dest = dest;
- }
-
- @Override
- public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)
- throws ChannelException {
- dest.messageReceived(msg);
- }
- }
-
- /**
- * Interceptor that simply captures the latest message sent to or received by it.
- */
- private static class ValueCaptureInterceptor
- extends ChannelInterceptorBase
- {
- private byte[] value;
-
- @Override
- public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)
- throws ChannelException {
- value = msg.getMessage().getBytes();
- }
-
- @Override
- public void messageReceived(ChannelMessage msg) {
- value = msg.getMessage().getBytes();
- }
-
- public byte[] getValue() {
- return value;
- }
- }
-
- /**
- * Interceptor that simply captures all messages sent to or received by it.
- */
- private static class ValuesCaptureInterceptor
- extends ChannelInterceptorBase
- {
- private ArrayList<byte[]> messages = new ArrayList<>();
-
- @Override
- public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)
- throws ChannelException {
- synchronized(messages) {
- messages.add(msg.getMessage().getBytes());
- }
- }
-
- @Override
- public void messageReceived(ChannelMessage msg) {
- synchronized(messages) {
- messages.add(msg.getMessage().getBytes());
- }
- }
-
- @SuppressWarnings("unchecked")
- public Collection<byte[]> getValues() {
- return (Collection<byte[]>)messages.clone();
- }
- }
}
diff --git a/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptorLargeHeap.java b/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptorLargeHeap.java
new file mode 100644
index 0000000000..81d02064da
--- /dev/null
+++ b/test/org/apache/catalina/tribes/group/interceptors/TestEncryptInterceptorLargeHeap.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.catalina.tribes.group.interceptors;
+
+import org.junit.Assert;
+import org.junit.FixMethodOrder;
+import org.junit.Test;
+import org.junit.runners.MethodSorters;
+
+import org.apache.catalina.tribes.Channel;
+
+/**
+ * Tests the EncryptInterceptor using very large inputs.
+ *
+ * Many of the tests in this class use strings as input and output, even
+ * though the interceptor actually operates on byte arrays. This is done
+ * for readability for the tests and their outputs.
+ */
+@FixMethodOrder(MethodSorters.NAME_ASCENDING)
+public class TestEncryptInterceptorLargeHeap extends EncryptionInterceptorBaseTest {
+
+ @Test
+ public void testHugePayload() throws Exception {
+ src.start(Channel.SND_TX_SEQ);
+ dest.start(Channel.SND_TX_SEQ);
+
+ byte[] bytes = new byte[1024*1024*1024];
+
+ Assert.assertArrayEquals("Huge payload roundtrip failed",
+ bytes,
+ roundTrip(bytes, src, dest));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org