You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/04/22 13:25:35 UTC
[commons-io] 01/04: Sort members
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit 551f39bcab991cfef7bf893efa223775fbc88bb3
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sat Apr 22 08:45:45 2023 -0400
Sort members
---
.../commons/io/input/QueueInputStreamTest.java | 90 +++++++++++-----------
1 file changed, 45 insertions(+), 45 deletions(-)
diff --git a/src/test/java/org/apache/commons/io/input/QueueInputStreamTest.java b/src/test/java/org/apache/commons/io/input/QueueInputStreamTest.java
index 6dce82c7..19f66ed0 100644
--- a/src/test/java/org/apache/commons/io/input/QueueInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/QueueInputStreamTest.java
@@ -111,6 +111,14 @@ public class QueueInputStreamTest {
return 8192;
}
+ @Test
+ public void invalidArguments() {
+ assertThrows(NullPointerException.class, () -> new QueueInputStream(null), "queue is required");
+ assertThrows(NullPointerException.class, () -> new QueueInputStream(new LinkedBlockingQueue<>(), null), "waitTime is required");
+ assertThrows(IllegalArgumentException.class, () -> new QueueInputStream(new LinkedBlockingQueue<>(), Duration.ofMillis(-1)),
+ "waitTime must not be negative");
+ }
+
private String readUnbuffered(final InputStream inputStream) throws IOException {
return readUnbuffered(inputStream, Integer.MAX_VALUE);
}
@@ -131,51 +139,6 @@ public class QueueInputStreamTest {
return byteArrayOutputStream.toString(StandardCharsets.UTF_8.name());
}
- @Test
- public void invalidArguments() {
- assertThrows(NullPointerException.class, () -> new QueueInputStream(null), "queue is required");
- assertThrows(NullPointerException.class, () -> new QueueInputStream(new LinkedBlockingQueue<>(), null), "waitTime is required");
- assertThrows(IllegalArgumentException.class, () -> new QueueInputStream(new LinkedBlockingQueue<>(), Duration.ofMillis(-1)),
- "waitTime must not be negative");
- }
-
- @ParameterizedTest(name = "inputData={0}")
- @MethodSource("inputData")
- public void unbufferedReadWrite(final String inputData) throws IOException {
- try (QueueInputStream inputStream = new QueueInputStream();
- final QueueOutputStream outputStream = inputStream.newQueueOutputStream()) {
- writeUnbuffered(outputStream, inputData);
- final String actualData = readUnbuffered(inputStream);
- assertEquals(inputData, actualData);
- }
- }
-
- @ParameterizedTest(name = "inputData={0}")
- @MethodSource("inputData")
- public void unbufferedReadWriteWithTimeout(final String inputData) throws IOException {
- try (QueueInputStream inputStream = new QueueInputStream(new LinkedBlockingQueue<>(), Duration.ofMinutes(2));
- final QueueOutputStream outputStream = inputStream.newQueueOutputStream()) {
- writeUnbuffered(outputStream, inputData);
- final String actualData = assertTimeout(Duration.ofSeconds(1), () -> readUnbuffered(inputStream, inputData.length()));
- assertEquals(inputData, actualData);
- }
- }
-
- @Test
- @DisplayName("If data is not available in queue, then read will wait until wait time elapses")
- public void timeoutUnavailableData() throws IOException {
- try (QueueInputStream inputStream = new QueueInputStream(new LinkedBlockingQueue<>(), Duration.ofMillis(500));
- final QueueOutputStream outputStream = inputStream.newQueueOutputStream()) {
-
- final Stopwatch stopwatch = Stopwatch.createStarted();
- final String actualData = assertTimeout(Duration.ofSeconds(1), () -> readUnbuffered(inputStream, 3));
- stopwatch.stop();
- assertEquals("", actualData);
-
- assertTrue(stopwatch.elapsed(TimeUnit.MILLISECONDS) >= 500);
- }
- }
-
@Test
@DisplayName("If read is interrupted while waiting, then exception is thrown")
public void timeoutInterrupted() throws Exception {
@@ -202,6 +165,43 @@ public class QueueInputStreamTest {
}
}
+ @Test
+ @DisplayName("If data is not available in queue, then read will wait until wait time elapses")
+ public void timeoutUnavailableData() throws IOException {
+ try (QueueInputStream inputStream = new QueueInputStream(new LinkedBlockingQueue<>(), Duration.ofMillis(500));
+ final QueueOutputStream outputStream = inputStream.newQueueOutputStream()) {
+
+ final Stopwatch stopwatch = Stopwatch.createStarted();
+ final String actualData = assertTimeout(Duration.ofSeconds(1), () -> readUnbuffered(inputStream, 3));
+ stopwatch.stop();
+ assertEquals("", actualData);
+
+ assertTrue(stopwatch.elapsed(TimeUnit.MILLISECONDS) >= 500);
+ }
+ }
+
+ @ParameterizedTest(name = "inputData={0}")
+ @MethodSource("inputData")
+ public void unbufferedReadWrite(final String inputData) throws IOException {
+ try (QueueInputStream inputStream = new QueueInputStream();
+ final QueueOutputStream outputStream = inputStream.newQueueOutputStream()) {
+ writeUnbuffered(outputStream, inputData);
+ final String actualData = readUnbuffered(inputStream);
+ assertEquals(inputData, actualData);
+ }
+ }
+
+ @ParameterizedTest(name = "inputData={0}")
+ @MethodSource("inputData")
+ public void unbufferedReadWriteWithTimeout(final String inputData) throws IOException {
+ try (QueueInputStream inputStream = new QueueInputStream(new LinkedBlockingQueue<>(), Duration.ofMinutes(2));
+ final QueueOutputStream outputStream = inputStream.newQueueOutputStream()) {
+ writeUnbuffered(outputStream, inputData);
+ final String actualData = assertTimeout(Duration.ofSeconds(1), () -> readUnbuffered(inputStream, inputData.length()));
+ assertEquals(inputData, actualData);
+ }
+ }
+
private void writeUnbuffered(final QueueOutputStream outputStream, final String inputData) throws IOException {
final byte[] bytes = inputData.getBytes(UTF_8);
outputStream.write(bytes, 0, bytes.length);