use of java.util.Base64.Encoder in project vert.x by eclipse.
the class Http2ServerTest method testQueuePushPromise.
@Test
public void testQueuePushPromise() throws Exception {
Context ctx = vertx.getOrCreateContext();
int numPushes = 10;
Set<String> pushSent = new HashSet<>();
server.requestHandler(req -> {
req.response().setChunked(true).write("abc");
for (int i = 0; i < numPushes; i++) {
int val = i;
String path = "/wibble" + val;
req.response().push(HttpMethod.GET, path, ar -> {
assertTrue(ar.succeeded());
assertSame(ctx, Vertx.currentContext());
pushSent.add(path);
vertx.setTimer(10, id -> {
ar.result().end("wibble-" + val);
});
});
}
});
startServer(ctx);
TestClient client = new TestClient();
client.settings.maxConcurrentStreams(3);
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
Http2ConnectionEncoder encoder = request.encoder;
encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.decoder.frameListener(new Http2FrameAdapter() {
int count = numPushes;
Set<String> pushReceived = new HashSet<>();
@Override
public void onPushPromiseRead(ChannelHandlerContext ctx, int streamId, int promisedStreamId, Http2Headers headers, int padding) throws Http2Exception {
pushReceived.add(headers.path().toString());
}
@Override
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception {
if (count-- == 0) {
vertx.runOnContext(v -> {
assertEquals(numPushes, pushSent.size());
assertEquals(pushReceived, pushSent);
testComplete();
});
}
return super.onDataRead(ctx, streamId, data, padding, endOfStream);
}
});
});
fut.sync();
await();
}
use of java.util.Base64.Encoder in project sonarqube by SonarSource.
the class UuidGeneratorImplTest method generate_from_FixedBase_concurrent_test.
@Test
public void generate_from_FixedBase_concurrent_test() throws InterruptedException {
UuidGenerator.WithFixedBase withFixedBase = underTest.withFixedBase();
int rounds = 500;
List<byte[]> uuids1 = new ArrayList<>(rounds);
List<byte[]> uuids2 = new ArrayList<>(rounds);
AtomicInteger cnt = new AtomicInteger();
Thread t1 = new Thread(() -> {
for (int i = 0; i < rounds; i++) {
uuids1.add(withFixedBase.generate(cnt.getAndIncrement()));
}
});
Thread t2 = new Thread(() -> {
for (int i = 0; i < rounds; i++) {
uuids2.add(withFixedBase.generate(cnt.getAndIncrement()));
}
});
t1.start();
t2.start();
t1.join();
t2.join();
Base64.Encoder encoder = Base64.getEncoder();
Set<String> uuids = new HashSet<>(rounds * 2);
uuids1.forEach(bytes -> uuids.add(encoder.encodeToString(bytes)));
uuids2.forEach(bytes -> uuids.add(encoder.encodeToString(bytes)));
assertThat(uuids).hasSize(rounds * 2);
}
use of java.util.Base64.Encoder in project j2objc by google.
the class Base64Test method testRoundTrip_wrap_url.
public void testRoundTrip_wrap_url() throws Exception {
Encoder encoder = Base64.getUrlEncoder();
Decoder decoder = Base64.getUrlDecoder();
checkRoundTrip_wrapInputStream(encoder, decoder);
}
use of java.util.Base64.Encoder in project j2objc by google.
the class Base64Test method testRoundtrip_wrap_mime.
public void testRoundtrip_wrap_mime() throws Exception {
Encoder encoder = Base64.getMimeEncoder();
Decoder decoder = Base64.getMimeDecoder();
checkRoundTrip_wrapInputStream(encoder, decoder);
}
use of java.util.Base64.Encoder in project j2objc by google.
the class Base64Test method checkWrapOutputStreamConsistentWithEncode.
private static void checkWrapOutputStreamConsistentWithEncode(Encoder encoder) throws Exception {
final Random random = new Random(32176L);
// one large write(byte[]) of the whole input
WriteStrategy allAtOnce = (bytes, out) -> out.write(bytes);
checkWrapOutputStreamConsistentWithEncode(encoder, allAtOnce);
// many calls to write(int)
WriteStrategy byteWise = (bytes, out) -> {
for (byte b : bytes) {
out.write(b);
}
};
checkWrapOutputStreamConsistentWithEncode(encoder, byteWise);
// intermixed sequences of write(int) with
// write(byte[],int,int) of various lengths.
WriteStrategy mixed = (bytes, out) -> {
int[] writeLengths = { -10, -5, -1, 0, 1, 1, 2, 2, 3, 10, 100 };
int p = 0;
while (p < bytes.length) {
int l = writeLengths[random.nextInt(writeLengths.length)];
l = Math.min(l, bytes.length - p);
if (l >= 0) {
out.write(bytes, p, l);
p += l;
} else {
l = Math.min(-l, bytes.length - p);
for (int i = 0; i < l; ++i) {
out.write(bytes[p + i]);
}
p += l;
}
}
};
checkWrapOutputStreamConsistentWithEncode(encoder, mixed);
}
Aggregations