Skip to content

Commit

Permalink
8290886: [11u]: Backport of JDK-8266250 introduced test failures
Browse files Browse the repository at this point in the history
Reviewed-by: clanger
  • Loading branch information
gdams authored and RealCLanger committed Jul 25, 2022
1 parent 69a3003 commit a1a0459
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
33 changes: 22 additions & 11 deletions test/jdk/java/net/httpclient/websocket/WebSocketProxyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.HexFormat;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
Expand Down Expand Up @@ -150,33 +149,45 @@ public Object[][] servers() {
};
}

record bytes(byte[] bytes) {
private static class Bytes {
private final byte[] bytes;
public Bytes(byte[] bytes) {
this.bytes = bytes;
}
public byte[] getBytes() {
return bytes;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o instanceof bytes other) {
return Arrays.equals(bytes(), other.bytes());
if (o instanceof byte[]) {
return Arrays.equals(bytes, (byte[]) o);
}
if (o instanceof Bytes) {
return Arrays.equals(bytes, ((Bytes) o).getBytes());
}
return false;
}
@Override
public int hashCode() { return Arrays.hashCode(bytes()); }
public int hashCode() { return Arrays.hashCode(bytes); }
public String toString() {
return "0x" + HexFormat.of()
.withUpperCase()
.formatHex(bytes());
StringBuilder builder = new StringBuilder("0x");
for (byte aByte : bytes) {
builder.append(String.format("%X", aByte).toUpperCase());
}
return builder.toString();
}
}

static List<bytes> ofBytes(List<byte[]> bytes) {
return bytes.stream().map(bytes::new).toList();
static List<Bytes> ofBytes(List<byte[]> bytes) {
return bytes.stream().map(WebSocketProxyTest.Bytes::new).collect(Collectors.toList());
}

static String diagnose(List<byte[]> a, List<byte[]> b) {
var actual = ofBytes(a);
var expected = ofBytes(b);
var message = actual.equals(expected) ? "match" : "differ";
return "%s and %s %s".formatted(actual, expected, message);
return String.format("%s and %s %s", actual, expected, message);
}

@Test(dataProvider = "servers")
Expand Down
33 changes: 22 additions & 11 deletions test/jdk/java/net/httpclient/websocket/WebSocketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
import java.util.HexFormat;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
Expand Down Expand Up @@ -434,33 +433,45 @@ public Object[][] servers() {
};
}

record bytes(byte[] bytes) {
private static class Bytes {
private final byte[] bytes;
public Bytes(byte[] bytes) {
this.bytes = bytes;
}
public byte[] getBytes() {
return bytes;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o instanceof bytes other) {
return Arrays.equals(bytes(), other.bytes());
if (o instanceof byte[]) {
return Arrays.equals(bytes, (byte[]) o);
}
if (o instanceof Bytes) {
return Arrays.equals(bytes, ((Bytes) o).getBytes());
}
return false;
}
@Override
public int hashCode() { return Arrays.hashCode(bytes()); }
public int hashCode() { return Arrays.hashCode(bytes); }
public String toString() {
return "0x" + HexFormat.of()
.withUpperCase()
.formatHex(bytes());
StringBuilder builder = new StringBuilder("0x");
for (byte aByte : bytes) {
builder.append(String.format("%X", aByte).toUpperCase());
}
return builder.toString();
}
}

static List<bytes> ofBytes(List<byte[]> bytes) {
return bytes.stream().map(bytes::new).toList();
static List<Bytes> ofBytes(List<byte[]> bytes) {
return bytes.stream().map(WebSocketTest.Bytes::new).collect(Collectors.toList());
}

static String diagnose(List<byte[]> a, List<byte[]> b) {
var actual = ofBytes(a);
var expected = ofBytes(b);
var message = actual.equals(expected) ? "match" : "differ";
return "%s and %s %s".formatted(actual, expected, message);
return String.format("%s and %s %s", actual, expected, message);
}

@Test(dataProvider = "servers")
Expand Down

1 comment on commit a1a0459

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.