コード例 #1
0
  @Test
  public void testStoreRequest() throws IOException {
    final RuleKey ruleKey = new RuleKey("00000000010000000000008000000000");
    final RuleKey ruleKey2 = new RuleKey("90000000000000000000008000000005");
    final String data = "data";
    ImmutableMap<String, String> metadata = ImmutableMap.of("metaKey", "metaValue");

    HttpArtifactCacheBinaryProtocol.StoreRequest storeRequest =
        new HttpArtifactCacheBinaryProtocol.StoreRequest(
            ArtifactInfo.builder().addRuleKeys(ruleKey, ruleKey2).setMetadata(metadata).build(),
            new ByteSource() {
              @Override
              public InputStream openStream() throws IOException {
                return new ByteArrayInputStream(data.getBytes(Charsets.UTF_8));
              }
            });

    ByteArrayOutputStream storeRequestOutputStream = new ByteArrayOutputStream();
    storeRequest.write(storeRequestOutputStream);

    ByteArrayOutputStream storeRequestPayloadStream = new ByteArrayOutputStream();
    StoreResponseReadResult readStoreRequest =
        HttpArtifactCacheBinaryProtocol.readStoreRequest(
            new DataInputStream(new ByteArrayInputStream(storeRequestOutputStream.toByteArray())),
            storeRequestPayloadStream);

    assertThat(readStoreRequest.getRuleKeys(), Matchers.containsInAnyOrder(ruleKey, ruleKey2));
    assertThat(readStoreRequest.getMetadata(), Matchers.equalTo(metadata));
    assertThat(
        storeRequestPayloadStream.toByteArray(), Matchers.equalTo(data.getBytes(Charsets.UTF_8)));
  }