(tomcat) 07/18: Refactor tests that require large heap to new category
This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git commit 5159b4966a1da42a6868f958822b7f4881dc Author: Mark Thomas AuthorDate: Wed Jan 3 10:13:33 2024 + Refactor tests that require large heap to new category These tests are still disabled by default but: - no not appear as skipped tests in a standard test run - can be enabled with a build property rather than a code change --- test/org/apache/tomcat/util/buf/TestByteChunk.java | 58 +++-- .../tomcat/util/buf/TestByteChunkLargeHeap.java| 60 ++ test/org/apache/tomcat/util/buf/TestCharChunk.java | 35 - ...tCharChunk.java => TestCharChunkLargeHeap.java} | 47 ++--- 4 files changed, 104 insertions(+), 96 deletions(-) diff --git a/test/org/apache/tomcat/util/buf/TestByteChunk.java b/test/org/apache/tomcat/util/buf/TestByteChunk.java index 618cd66a01..ce8234230e 100644 --- a/test/org/apache/tomcat/util/buf/TestByteChunk.java +++ b/test/org/apache/tomcat/util/buf/TestByteChunk.java @@ -16,17 +16,17 @@ */ package org.apache.tomcat.util.buf; -import java.io.IOException; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; -import org.apache.tomcat.util.buf.ByteChunk.ByteOutputChannel; - /** * Test cases for {@link ByteChunk}. */ @@ -144,33 +144,39 @@ public class TestByteChunk { } -@Ignore // Requires a 6GB heap (on markt's desktop - YMMV) @Test -public void testAppend() throws Exception { -ByteChunk bc = new ByteChunk(); -bc.setByteOutputChannel(new Sink()); -// Defaults to no limit +public void testSerialization() throws Exception { +String data = "Hello world!"; +byte[] bytes = data.getBytes(StandardCharsets.UTF_8); -byte data[] = new byte[32 * 1024 * 1024]; +ByteChunk bcIn = new ByteChunk(); +bcIn.setBytes(bytes, 0, bytes.length); +bcIn.setCharset(StandardCharsets.UTF_8); -for (int i = 0; i < 100; i++) { -bc.append(data, 0, data.length); -} - -Assert.assertEquals(AbstractChunk.ARRAY_MAX_SIZE, bc.getBuffer().length); -} +ByteArrayOutputStream baos = new ByteArrayOutputStream(); +ObjectOutputStream oos = new ObjectOutputStream(baos); +oos.writeObject(bcIn); +oos.close(); +ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); +ObjectInputStream ois = new ObjectInputStream(bais); +ByteChunk bcOut = (ByteChunk) ois.readObject(); -public class Sink implements ByteOutputChannel { +Assert.assertArrayEquals(bytes, bcOut.getBytes()); +Assert.assertEquals(bcIn.getCharset(), bcOut.getCharset()); +} -@Override -public void realWriteBytes(byte[] cbuf, int off, int len) throws IOException { -// NO-OP -} -@Override -public void realWriteBytes(ByteBuffer from) throws IOException { -// NO-OP -} +@Test +public void testToString() { +ByteChunk bc = new ByteChunk(); +Assert.assertNull(bc.toString()); +byte[] data = new byte[8]; +bc.setBytes(data, 0, data.length); +Assert.assertNotNull(bc.toString()); +bc.recycle(); +// toString() should behave consistently for new ByteChunk and +// immediately after a call to recycle(). +Assert.assertNull(bc.toString()); } } diff --git a/test/org/apache/tomcat/util/buf/TestByteChunkLargeHeap.java b/test/org/apache/tomcat/util/buf/TestByteChunkLargeHeap.java new file mode 100644 index 00..e0b0f2f605 --- /dev/null +++ b/test/org/apache/tomcat/util/buf/TestByteChunkLargeHeap.java @@ -0,0 +1,60 @@ +/* + * 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
(tomcat) 07/18: Refactor tests that require large heap to new category
This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git commit 617152d7de20e7f9377d9998b5d6af155f524b7c Author: Mark Thomas AuthorDate: Wed Jan 3 10:13:33 2024 + Refactor tests that require large heap to new category These tests are still disabled by default but: - no not appear as skipped tests in a standard test run - can be enabled with a build property rather than a code change --- test/org/apache/tomcat/util/buf/TestByteChunk.java | 36 - .../tomcat/util/buf/TestByteChunkLargeHeap.java| 60 ++ test/org/apache/tomcat/util/buf/TestCharChunk.java | 31 --- .../tomcat/util/buf/TestCharChunkLargeHeap.java| 55 4 files changed, 115 insertions(+), 67 deletions(-) diff --git a/test/org/apache/tomcat/util/buf/TestByteChunk.java b/test/org/apache/tomcat/util/buf/TestByteChunk.java index 0299e891e1..ce8234230e 100644 --- a/test/org/apache/tomcat/util/buf/TestByteChunk.java +++ b/test/org/apache/tomcat/util/buf/TestByteChunk.java @@ -18,20 +18,15 @@ package org.apache.tomcat.util.buf; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.UnsupportedEncodingException; -import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.Arrays; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; -import org.apache.tomcat.util.buf.ByteChunk.ByteOutputChannel; - /** * Test cases for {@link ByteChunk}. */ @@ -172,37 +167,6 @@ public class TestByteChunk { } -@Ignore // Requires a 6GB heap (on markt's desktop - YMMV) -@Test -public void testAppend() throws Exception { -ByteChunk bc = new ByteChunk(); -bc.setByteOutputChannel(new Sink()); -// Defaults to no limit - -byte data[] = new byte[32 * 1024 * 1024]; - -for (int i = 0; i < 100; i++) { -bc.append(data, 0, data.length); -} - -Assert.assertEquals(AbstractChunk.ARRAY_MAX_SIZE, bc.getBuffer().length); -} - - -public static class Sink implements ByteOutputChannel { - -@Override -public void realWriteBytes(byte[] cbuf, int off, int len) throws IOException { -// NO-OP -} - -@Override -public void realWriteBytes(ByteBuffer from) throws IOException { -// NO-OP -} -} - - @Test public void testToString() { ByteChunk bc = new ByteChunk(); diff --git a/test/org/apache/tomcat/util/buf/TestByteChunkLargeHeap.java b/test/org/apache/tomcat/util/buf/TestByteChunkLargeHeap.java new file mode 100644 index 00..e0b0f2f605 --- /dev/null +++ b/test/org/apache/tomcat/util/buf/TestByteChunkLargeHeap.java @@ -0,0 +1,60 @@ +/* + * 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.tomcat.util.buf; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.tomcat.util.buf.ByteChunk.ByteOutputChannel; + +/** + * Test cases for {@link ByteChunk} that require a large heap. + */ +public class TestByteChunkLargeHeap { + +@Test +public void testAppend() throws Exception { +ByteChunk bc = new ByteChunk(); +bc.setByteOutputChannel(new Sink()); +// Defaults to no limit + +byte data[] = new byte[32 * 1024 * 1024]; + +for (int i = 0; i < 100; i++) { +bc.append(data, 0, data.length); +} + +Assert.assertEquals(AbstractChunk.ARRAY_MAX_SIZE, bc.getBuffer().length); +} + + +public static class Sink implements ByteOutputChannel { + +@Override +public void realWriteBytes(byte[] cbuf, int off, int len) throws IOException { +// NO-OP +} + +@Override +public void realWriteBytes(ByteBuffer from) throws IOException { +// NO-OP +} +} +} diff --git a/test/org/apache/tomcat/util/buf/TestCharChunk.java