< prev index next >
test/jdk/java/net/httpclient/http2/jdk.incubator.httpclient/jdk/incubator/http/internal/hpack/BinaryPrimitivesTest.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -22,10 +22,12 @@
*/
package jdk.incubator.http.internal.hpack;
import org.testng.annotations.Test;
+import java.io.IOException;
+import java.io.UncheckedIOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@@ -78,11 +80,11 @@
// Since readInteger(x) is the inverse of writeInteger(x), thus:
//
// for all x: readInteger(writeInteger(x)) == x
//
@Test
- public void integerIdentity() {
+ public void integerIdentity() throws IOException {
final int MAX_VALUE = 1 << 22;
int totalCases = 0;
int maxFilling = 0;
IntegerReader r = new IntegerReader();
IntegerWriter w = new IntegerWriter();
@@ -117,11 +119,15 @@
forEachSplit(bb,
(buffers) -> {
Iterable<? extends ByteBuffer> buf = relocateBuffers(injectEmptyBuffers(buffers));
r.configure(N);
for (ByteBuffer b : buf) {
+ try {
r.read(b);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
}
assertEquals(r.get(), expected);
r.reset();
});
bb.clear();
@@ -153,11 +159,15 @@
b.position(pos);
}
if (!written) {
fail("please increase bb size");
}
+ try {
r.configure(N).read(concat(buf));
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
// TODO: check payload here
assertEquals(r.get(), expected);
w.reset();
r.reset();
bb.clear();
@@ -170,11 +180,11 @@
// Since readString(x) is the inverse of writeString(x), thus:
//
// for all x: readString(writeString(x)) == x
//
@Test
- public void stringIdentity() {
+ public void stringIdentity() throws IOException {
final int MAX_STRING_LENGTH = 4096;
ByteBuffer bytes = ByteBuffer.allocate(MAX_STRING_LENGTH + 6); // it takes 6 bytes to encode string length of Integer.MAX_VALUE
CharBuffer chars = CharBuffer.allocate(MAX_STRING_LENGTH);
StringReader reader = new StringReader();
StringWriter writer = new StringWriter();
@@ -239,11 +249,15 @@
buf.position(p0);
}
if (!written) {
fail("please increase 'bytes' size");
}
+ try {
reader.read(concat(buffers), chars);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
chars.flip();
assertEquals(chars.toString(), expected);
reader.reset();
writer.reset();
chars.clear();
@@ -277,11 +291,15 @@
bytes.flip();
forEachSplit(bytes, (buffers) -> {
for (ByteBuffer buf : buffers) {
int p0 = buf.position();
+ try {
reader.read(buf, chars);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
buf.position(p0);
}
chars.flip();
assertEquals(chars.toString(), expected);
reader.reset();
@@ -331,11 +349,15 @@
}
private static void verifyRead(byte[] data, int expected, int N) {
ByteBuffer buf = ByteBuffer.wrap(data, 0, data.length);
IntegerReader reader = new IntegerReader();
+ try {
reader.configure(N).read(buf);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
assertEquals(expected, reader.get());
}
private void verifyWrite(byte[] expected, int data, int N) {
IntegerWriter w = new IntegerWriter();
< prev index next >