@Test public void serializeResponse() throws Exception { final ByteBuf serialized = marshaller.serializeResponse(GrpcTestUtil.RESPONSE_MESSAGE); assertThat(ByteBufUtil.getBytes(serialized)) .containsExactly(GrpcTestUtil.RESPONSE_MESSAGE.toByteArray()); serialized.release(); }
@Test public void serializeRequest() throws Exception { final ByteBuf serialized = marshaller.serializeRequest(GrpcTestUtil.REQUEST_MESSAGE); assertThat(ByteBufUtil.getBytes(serialized)) .containsExactly(GrpcTestUtil.REQUEST_MESSAGE.toByteArray()); serialized.release(); }
@Test public void grpcWeb() throws Exception { final HttpClient client = HttpClient.of(server.httpUri("/")); final AggregatedHttpMessage response = client.execute( HttpHeaders.of(HttpMethod.POST, UnitTestServiceGrpc.getStaticUnaryCallMethod().getFullMethodName()) .set(HttpHeaderNames.CONTENT_TYPE, "application/grpc-web"), GrpcTestUtil.uncompressedFrame(GrpcTestUtil.requestByteBuf())).aggregate().get(); final byte[] serializedStatusHeader = "grpc-status: 0\r\n".getBytes(StandardCharsets.US_ASCII); final byte[] serializedTrailers = Bytes.concat( new byte[] { ArmeriaServerCall.TRAILERS_FRAME_HEADER }, Ints.toByteArray(serializedStatusHeader.length), serializedStatusHeader); assertThat(response.content().array()).containsExactly( Bytes.concat( GrpcTestUtil.uncompressedFrame( GrpcTestUtil.protoByteBuf(RESPONSE_MESSAGE)), serializedTrailers)); checkRequestLog((rpcReq, rpcRes, grpcStatus) -> { assertThat(rpcReq.method()).isEqualTo("armeria.grpc.testing.UnitTestService/StaticUnaryCall"); assertThat(rpcReq.params()).containsExactly(REQUEST_MESSAGE); assertThat(rpcRes.get()).isEqualTo(RESPONSE_MESSAGE); }); }
@Test public void migrateRevertsUncommittedWritesAndMigratesMostRecentlyCommitted() { fromKvs.createTables(TEST_AND_CHECKPOINT_TABLES); fromTxManager.runTaskWithRetry(tx -> { tx.put(TEST_TABLE, ImmutableMap.of(TEST_CELL, TEST_VALUE1)); return tx.getTimestamp(); }); long uncommittedTs = fromServices.getTimestampService().getFreshTimestamp(); fromKvs.put(TEST_TABLE, ImmutableMap.of(TEST_CELL, TEST_VALUE2), uncommittedTs); KeyValueServiceMigrator migrator = KeyValueServiceMigrators.setupMigrator(migratorSpec); migrator.setup(); migrator.migrate(); assertThat(fromServices.getTransactionService().get(uncommittedTs)) .isEqualTo(TransactionConstants.FAILED_COMMIT_TS); assertThat(toKvs.get(TEST_TABLE, ImmutableMap.of(TEST_CELL, Long.MAX_VALUE)).get(TEST_CELL).getContents()) .containsExactly(TEST_VALUE1); }
@Test public void multipartUpload() throws Exception { MultiValueMap<String, Object> multipartData = new LinkedMultiValueMap<>(); multipartData.add("file", new byte[] { 1, 2, 3, 4 }); ExchangeResult result = WebTestClient .bindToRouterFunction(RouterFunctions.route(POST("/foo"), (req) -> { req.body(BodyExtractors.toMultipartData()).block(); return null; })).configureClient().baseUrl("http://localhost").build().post() .uri("/foo").body(BodyInserters.fromMultipartData(multipartData)) .exchange().expectBody().returnResult(); OperationRequest request = this.converter.convert(result); assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo")); assertThat(request.getMethod()).isEqualTo(HttpMethod.POST); assertThat(request.getParts()).hasSize(1); OperationRequestPart part = request.getParts().iterator().next(); assertThat(part.getName()).isEqualTo("file"); assertThat(part.getSubmittedFileName()).isNull(); assertThat(part.getHeaders()).hasSize(2); assertThat(part.getHeaders().getContentLength()).isEqualTo(4L); assertThat(part.getHeaders().getContentDisposition().getName()).isEqualTo("file"); assertThat(part.getContent()).containsExactly(1, 2, 3, 4); }
@Test public void tablesDelegatedToSourceKvsGetDroppedFromSourceKvsIfMigratable() { fromKvs.createTable(FAKE_ATOMIC_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA); fromKvs.putUnlessExists(FAKE_ATOMIC_TABLE, ImmutableMap.of(TEST_CELL, TEST_VALUE1)); KeyValueService toTableSplittingKvs = TableSplittingKeyValueService.create( ImmutableList.of(new InMemoryKeyValueService(false), fromKvs), ImmutableMap.of(FAKE_ATOMIC_TABLE, fromKvs)); AtlasDbServices toSplittingServices = createMock(toTableSplittingKvs); ImmutableMigratorSpec spec = ImmutableMigratorSpec.builder() .fromServices(fromServices) .toServices(toSplittingServices) .build(); assertThat(toSplittingServices.getKeyValueService() .get(FAKE_ATOMIC_TABLE, ImmutableMap.of(TEST_CELL, 1L)).get(TEST_CELL).getContents()) .containsExactly(TEST_VALUE1); KeyValueServiceMigrator migrator = KeyValueServiceMigrators.setupMigrator(spec); migrator.setup(); assertThat(fromKvs.getAllTableNames()).doesNotContain(FAKE_ATOMIC_TABLE); }
assertThat(contentDisposition.getFilename()).isEqualTo("image.png"); assertThat(part.getHeaders().getContentType()).isEqualTo(MediaType.IMAGE_PNG); assertThat(part.getContent()).containsExactly(1, 2, 3, 4);
@Test public void testBytesAlignedAlignOddStringLength() { byte[] bytes = HexUtils.asBytesAligned("10203", 4); assertThat(bytes).containsExactly(0x00, 0x01, 0x02, 0x03); } }
@Test public void testLeadingZero() { byte[] decoded = Base58CheckUtils.decode("15sPzhL1ouhNBTAtdT"); assertThat(decoded).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); }
@Test public void testMultipleLeadingZeros() { byte[] decoded = Base58CheckUtils.decode("111kdY9bfye13qL4rbC4"); assertThat(decoded).containsExactly(0, 0, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1); }
@Test public void testOneByteZero() { byte[] decoded = Base58CheckUtils.decode("1Wh4bh"); assertThat(decoded).containsExactly(0); }
/** * Even though there should never be a null body, it does happen. See JAMES-2384 */ @Test public void getFullContentShouldReturnOriginalContentWhenBodyFieldIsNull() throws Exception { // Prepare the message byte[] content = "Subject: the null message".getBytes(StandardCharsets.UTF_8); JPAMailboxMessage message = new JPAMailboxMessage(content, null); // Get and check assertThat(IOUtils.toByteArray(message.getFullContent())).containsExactly(content); }
@Test public void testThreeByteVarInt() { VarInt varIntMin = VarInt.of(0xFDL); assertThat(varIntMin.toString()).isEqualTo("fdfd00"); assertThat(varIntMin.asLitEndBytes()).containsExactly(0xFD, 0xFD, 0x00); VarInt varInt1000 = VarInt.of(0x3E8L); assertThat(varInt1000.toString()).isEqualTo("fde803"); assertThat(varInt1000.asLitEndBytes()).containsExactly(0xFD, 0xE8, 0x03); VarInt varIntMax = VarInt.of(0xFFFFL); assertThat(varIntMax.toString()).isEqualTo("fdffff"); assertThat(varIntMax.asLitEndBytes()).containsExactly(0xFD, 0xFF, 0xFF); }
@Test public void testFiveByteVarInt() { VarInt varIntMin = VarInt.of(0x10000L); assertThat(varIntMin.toString()).isEqualTo("fe00000100"); assertThat(varIntMin.asLitEndBytes()).containsExactly(0xFE, 0x00, 0x00, 0x01, 0x00); VarInt varIntAllBytes = VarInt.of(0xAABBCCDDL); assertThat(varIntAllBytes.toString()).isEqualTo("feddccbbaa"); assertThat(varIntAllBytes.asLitEndBytes()).containsExactly(0xFE, 0xDD, 0xCC, 0xBB, 0xAA); VarInt varIntMax = VarInt.of(0xFFFFFFFFL); assertThat(varIntMax.toString()).isEqualTo("feffffffff"); assertThat(varIntMax.asLitEndBytes()).containsExactly(0xFE, 0xFF, 0xFF, 0xFF, 0xFF); }
@Test public void serializesOnlyNonEmptyByteArray() throws Exception { JsonAdapter<Data1> adapter = moshi.adapter(Data1.class); Data1 fromJson = adapter.fromJson("{\n" + "\"byteArray\": [1]\n" + "}"); assertThat(fromJson.byteArray).containsExactly((byte) 1); fromJson.byteArray = new byte[0]; assertThat(adapter.toJson(fromJson)).isEqualTo("{}"); fromJson.byteArray = new byte[] { 5 }; assertThat(adapter.toJson(fromJson)).isEqualTo("{\"byteArray\":[5]}"); }
@Test public void testMinValue() { ULong value = ULong.of(0); assertThat(value.toString()).isEqualTo("0000000000000000"); assertThat(value.asLitEndBytes()).containsExactly(0, 0, 0, 0, 0, 0, 0, 0); }
@Test public void testMaxValue() { ULong value = ULong.of(0xFFFFFFFFFFFFFFFFL); assertThat(value.toString()).isEqualTo("ffffffffffffffff"); assertThat(value.asLitEndBytes()).containsExactly(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); }
@Test public void testDiffBytes() { ULong value = ULong.of(0x1122334455667788L); assertThat(value.toString()).isEqualTo("8877665544332211"); assertThat(value.asLitEndBytes()).containsExactly(0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11); } }
@Test public void parseBytesOrNullTestForValidValue() throws Exception { // Do byte[] bytes = BeaconContentUtil.parseBytesOrNull("0123"); // Verify assertThat(bytes).containsExactly(0x01, 0x23); }
public void checkBlobContent(String blobId, byte[] rawBytes) { byte[] attachmentBytes = with() .header("Authorization", accessToken.serialize()) .get("/download/" + blobId) .then() .extract() .body() .asByteArray(); assertThat(attachmentBytes).containsExactly(rawBytes); }