コード例 #1
0
  public void testWriteMapOfLists() throws IOException {
    final int size = randomIntBetween(0, 5);
    final Map<String, List<String>> expected = new HashMap<>(size);

    for (int i = 0; i < size; ++i) {
      int listSize = randomIntBetween(0, 5);
      List<String> list = new ArrayList<>(listSize);

      for (int j = 0; j < listSize; ++j) {
        list.add(randomAsciiOfLength(5));
      }

      expected.put(randomAsciiOfLength(2), list);
    }

    final BytesStreamOutput out = new BytesStreamOutput();
    out.writeMapOfLists(expected);

    final StreamInput in = StreamInput.wrap(BytesReference.toBytes(out.bytes()));

    final Map<String, List<String>> loaded = in.readMapOfLists();

    assertThat(loaded.size(), equalTo(expected.size()));

    for (Map.Entry<String, List<String>> entry : expected.entrySet()) {
      assertThat(loaded.containsKey(entry.getKey()), equalTo(true));

      List<String> loadedList = loaded.get(entry.getKey());

      assertThat(loadedList, hasSize(entry.getValue().size()));

      for (int i = 0; i < loadedList.size(); ++i) {
        assertEquals(entry.getValue().get(i), loadedList.get(i));
      }
    }

    assertEquals(0, in.available());

    in.close();
    out.close();
  }
コード例 #2
0
 public ElasticsearchException(StreamInput in) throws IOException {
   super(in.readOptionalString(), in.readException());
   readStackTrace(this, in);
   headers.putAll(in.readMapOfLists(StreamInput::readString, StreamInput::readString));
 }