@Override
 protected void doReadFrom(StreamInput in) throws IOException {
   if (in.readBoolean()) {
     reduceScript = new Script(in);
   }
   aggregation = in.readGenericValue();
 }
示例#2
0
    public IndexMetaDataDiff(StreamInput in) throws IOException {
      index = in.readString();
      version = in.readLong();
      state = State.fromId(in.readByte());
      settings = Settings.readSettingsFromStream(in);
      mappings =
          DiffableUtils.readImmutableOpenMapDiff(
              in, DiffableUtils.getStringKeySerializer(), MappingMetaData.PROTO);
      aliases =
          DiffableUtils.readImmutableOpenMapDiff(
              in, DiffableUtils.getStringKeySerializer(), AliasMetaData.PROTO);
      customs =
          DiffableUtils.readImmutableOpenMapDiff(
              in,
              DiffableUtils.getStringKeySerializer(),
              new DiffableUtils.DiffableValueSerializer<String, Custom>() {
                @Override
                public Custom read(StreamInput in, String key) throws IOException {
                  return lookupPrototypeSafe(key).readFrom(in);
                }

                @Override
                public Diff<Custom> readDiff(StreamInput in, String key) throws IOException {
                  return lookupPrototypeSafe(key).readDiffFrom(in);
                }
              });
      activeAllocationIds =
          DiffableUtils.readImmutableOpenIntMapDiff(
              in,
              DiffableUtils.getVIntKeySerializer(),
              DiffableUtils.StringSetValueSerializer.getInstance());
    }
示例#3
0
 @Override
 public void readFrom(StreamInput in) throws IOException {
   fieldEvictions = in.readVLong();
   fieldSize = in.readVLong();
   filterSize = in.readVLong();
   bloomSize = in.readVLong();
 }
  public void testWriteStreamableList() throws IOException {
    final int size = randomIntBetween(0, 5);
    final List<TestStreamable> expected = new ArrayList<>(size);

    for (int i = 0; i < size; ++i) {
      expected.add(new TestStreamable(randomBoolean()));
    }

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

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

    final List<TestStreamable> loaded = in.readStreamableList(TestStreamable::new);

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

    for (int i = 0; i < expected.size(); ++i) {
      assertEquals(expected.get(i).value, loaded.get(i).value);
    }

    assertEquals(0, in.available());

    in.close();
    out.close();
  }
  public void testStreamInputBulkReadWithOffset() throws IOException {
    final int length = randomIntBetween(10, scaledRandomIntBetween(PAGE_SIZE * 2, PAGE_SIZE * 20));
    BytesReference pbr = newBytesReference(length);
    StreamInput si = pbr.streamInput();
    assertNotNull(si);

    // read a bunch of single bytes one by one
    int offset = randomIntBetween(1, length / 2);
    for (int i = 0; i < offset; i++) {
      assertEquals(si.available(), length - i);
      assertEquals(pbr.get(i), si.readByte());
    }

    // now do NOT reset the stream - keep the stream's offset!

    // buffer to compare remaining bytes against bulk read
    byte[] pbrBytesWithOffset = Arrays.copyOfRange(pbr.toBytes(), offset, length);
    // randomized target buffer to ensure no stale slots
    byte[] targetBytes = new byte[pbrBytesWithOffset.length];
    random().nextBytes(targetBytes);

    // bulk-read all
    si.readFully(targetBytes);
    assertArrayEquals(pbrBytesWithOffset, targetBytes);
    assertEquals(si.available(), 0);
  }
 @Override
 public void readFrom(StreamInput in) throws IOException {
   super.readFrom(in);
   valid = in.readBoolean();
   explanation = in.readOptionalString();
   error = in.readOptionalString();
 }
示例#7
0
 @Override
 public void readFrom(StreamInput in) throws IOException {
   version = in.readString();
   vmName = in.readString();
   vmVersion = in.readString();
   vmVendor = in.readString();
 }
  public void testNamedWriteableUnknownNamedWriteable() throws IOException {
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry();
    namedWriteableRegistry.register(
        BaseNamedWriteable.class, TestNamedWriteable.NAME, TestNamedWriteable::new);
    BytesStreamOutput out = new BytesStreamOutput();
    out.writeNamedWriteable(
        new NamedWriteable() {
          @Override
          public String getWriteableName() {
            return "unknown";
          }

          @Override
          public void writeTo(StreamOutput out) throws IOException {}
        });
    StreamInput in =
        new NamedWriteableAwareStreamInput(
            StreamInput.wrap(BytesReference.toBytes(out.bytes())), namedWriteableRegistry);
    try {
      // no named writeable registered with given name under test category, can write but cannot
      // read it back
      in.readNamedWriteable(BaseNamedWriteable.class);
      fail("read should have failed");
    } catch (IllegalArgumentException e) {
      assertThat(
          e.getMessage(),
          equalTo("unknown named writeable [" + BaseNamedWriteable.class.getName() + "][unknown]"));
    }
  }
 public void testWriteableReaderReturnsWrongName() throws IOException {
   BytesStreamOutput out = new BytesStreamOutput();
   NamedWriteableRegistry namedWriteableRegistry =
       new NamedWriteableRegistry(
           Collections.singletonList(
               new NamedWriteableRegistry.Entry(
                   BaseNamedWriteable.class,
                   TestNamedWriteable.NAME,
                   (StreamInput in) ->
                       new TestNamedWriteable(in) {
                         @Override
                         public String getWriteableName() {
                           return "intentionally-broken";
                         }
                       })));
   TestNamedWriteable namedWriteableIn =
       new TestNamedWriteable(
           randomAsciiOfLengthBetween(1, 10), randomAsciiOfLengthBetween(1, 10));
   out.writeNamedWriteable(namedWriteableIn);
   byte[] bytes = BytesReference.toBytes(out.bytes());
   StreamInput in =
       new NamedWriteableAwareStreamInput(StreamInput.wrap(bytes), namedWriteableRegistry);
   assertEquals(in.available(), bytes.length);
   AssertionError e =
       expectThrows(AssertionError.class, () -> in.readNamedWriteable(BaseNamedWriteable.class));
   assertThat(
       e.getMessage(),
       endsWith(
           " claims to have a different name [intentionally-broken] than it was read from [test-named-writeable]."));
 }
  @Override
  public void readFrom(StreamInput in) throws IOException {
    shardId = ShardId.readShardId(in);
    int size = in.readVInt();
    phase1FileNames = new ArrayList<String>(size);
    for (int i = 0; i < size; i++) {
      phase1FileNames.add(in.readUTF());
    }

    size = in.readVInt();
    phase1FileSizes = new ArrayList<Long>(size);
    for (int i = 0; i < size; i++) {
      phase1FileSizes.add(in.readVLong());
    }

    size = in.readVInt();
    phase1ExistingFileNames = new ArrayList<String>(size);
    for (int i = 0; i < size; i++) {
      phase1ExistingFileNames.add(in.readUTF());
    }

    size = in.readVInt();
    phase1ExistingFileSizes = new ArrayList<Long>(size);
    for (int i = 0; i < size; i++) {
      phase1ExistingFileSizes.add(in.readVLong());
    }

    phase1TotalSize = in.readVLong();
    phase1ExistingTotalSize = in.readVLong();
  }
示例#11
0
 @Override
 public void readFrom(StreamInput in) throws IOException {
   super.readFrom(in);
   if (in.getVersion().onOrAfter(version1)) {
     value2 = in.readInt();
   }
 }
示例#12
0
    public MetaDataDiff(StreamInput in) throws IOException {
      clusterUUID = in.readString();
      version = in.readLong();
      transientSettings = Settings.readSettingsFromStream(in);
      persistentSettings = Settings.readSettingsFromStream(in);
      indices =
          DiffableUtils.readImmutableOpenMapDiff(
              in, DiffableUtils.getStringKeySerializer(), IndexMetaData.PROTO);
      templates =
          DiffableUtils.readImmutableOpenMapDiff(
              in, DiffableUtils.getStringKeySerializer(), IndexTemplateMetaData.PROTO);
      customs =
          DiffableUtils.readImmutableOpenMapDiff(
              in,
              DiffableUtils.getStringKeySerializer(),
              new DiffableUtils.DiffableValueSerializer<String, Custom>() {
                @Override
                public Custom read(StreamInput in, String key) throws IOException {
                  return lookupPrototypeSafe(key).readFrom(in);
                }

                @Override
                public Diff<Custom> readDiff(StreamInput in, String key) throws IOException {
                  return lookupPrototypeSafe(key).readDiffFrom(in);
                }
              });
    }
 public void testRandomReads() throws IOException {
   int length = randomIntBetween(10, scaledRandomIntBetween(PAGE_SIZE * 2, PAGE_SIZE * 20));
   BytesReference pbr = newBytesReference(length);
   StreamInput streamInput = pbr.streamInput();
   BytesRefBuilder target = new BytesRefBuilder();
   while (target.length() < pbr.length()) {
     switch (randomIntBetween(0, 10)) {
       case 6:
       case 5:
         target.append(new BytesRef(new byte[] {streamInput.readByte()}));
         break;
       case 4:
       case 3:
         BytesRef bytesRef =
             streamInput.readBytesRef(scaledRandomIntBetween(1, pbr.length() - target.length()));
         target.append(bytesRef);
         break;
       default:
         byte[] buffer = new byte[scaledRandomIntBetween(1, pbr.length() - target.length())];
         int offset = scaledRandomIntBetween(0, buffer.length - 1);
         int read = streamInput.read(buffer, offset, buffer.length - offset);
         target.append(new BytesRef(buffer, offset, read));
         break;
     }
   }
   assertEquals(pbr.length(), target.length());
   BytesRef targetBytes = target.get();
   assertArrayEquals(
       pbr.toBytes(),
       Arrays.copyOfRange(targetBytes.bytes, targetBytes.offset, targetBytes.length));
 }
示例#14
0
 @Override
 public void readFrom(StreamInput in) throws IOException {
   total = in.readVInt();
   masterOnly = in.readVInt();
   dataOnly = in.readVInt();
   masterData = in.readVInt();
   client = in.readVInt();
 }
示例#15
0
 @Override
 public void readFrom(StreamInput in) throws IOException {
   name = in.readUTF();
   length = in.readVLong();
   if (in.readBoolean()) {
     checksum = in.readUTF();
   }
 }
 /** Read from a stream. */
 public SpanNearQueryBuilder(StreamInput in) throws IOException {
   super(in);
   for (QueryBuilder<?> clause : readQueries(in)) {
     this.clauses.add((SpanQueryBuilder<?>) clause);
   }
   slop = in.readVInt();
   inOrder = in.readBoolean();
 }
 @Override
 public void readFrom(StreamInput in) throws IOException {
   super.readFrom(in);
   stage = SnapshotIndexShardStage.fromValue(in.readByte());
   stats = SnapshotStats.readSnapshotStats(in);
   nodeId = in.readOptionalString();
   failure = in.readOptionalString();
 }
示例#18
0
 @Override
 public void readFrom(StreamInput in) throws IOException {
   if (in.readBoolean()) {
     query = Symbol.fromStream(in);
   } else {
     noMatch = in.readBoolean();
   }
 }
 public static Settings readSettingsFromStream(StreamInput in) throws IOException {
   Builder builder = new Builder();
   int numberOfSettings = in.readVInt();
   for (int i = 0; i < numberOfSettings; i++) {
     builder.put(in.readString(), in.readString());
   }
   return builder.build();
 }
 @Override
 public void readFrom(StreamInput in) throws IOException {
   term = in.readString();
   startOffset = in.readInt();
   endOffset = in.readInt();
   position = in.readVInt();
   type = in.readOptionalString();
 }
 /** Read from a Stream. */
 public SignificantTermsAggregationBuilder(StreamInput in) throws IOException {
   super(in, TYPE, ValuesSourceType.ANY);
   bucketCountThresholds = new BucketCountThresholds(in);
   executionHint = in.readOptionalString();
   filterBuilder = in.readOptionalNamedWriteable(QueryBuilder.class);
   includeExclude = in.readOptionalWriteable(IncludeExclude::new);
   significanceHeuristic = in.readNamedWriteable(SignificanceHeuristic.class);
 }
示例#22
0
 @Override
 public void readFrom(StreamInput in) throws IOException {
   count = in.readVInt();
   cpuPercent = in.readVInt();
   totalOpenFileDescriptors = in.readVLong();
   minOpenFileDescriptors = in.readLong();
   maxOpenFileDescriptors = in.readLong();
 }
示例#23
0
 Cgroup(final StreamInput in) throws IOException {
   cpuAcctControlGroup = in.readString();
   cpuAcctUsageNanos = in.readLong();
   cpuControlGroup = in.readString();
   cpuCfsPeriodMicros = in.readLong();
   cpuCfsQuotaMicros = in.readLong();
   cpuStat = new CpuStat(in);
 }
 private <T extends Throwable> T serialize(T exception) throws IOException {
   ElasticsearchAssertions.assertVersionSerializable(
       VersionUtils.randomVersion(random()), exception);
   BytesStreamOutput out = new BytesStreamOutput();
   out.writeThrowable(exception);
   StreamInput in = StreamInput.wrap(out.bytes());
   return in.readThrowable();
 }
示例#25
0
 @Override
 public void readFrom(StreamInput in) throws IOException {
   heapInit = in.readVLong();
   heapMax = in.readVLong();
   nonHeapInit = in.readVLong();
   nonHeapMax = in.readVLong();
   directMemoryMax = in.readVLong();
 }
示例#26
0
 public Cpu(StreamInput in) throws IOException {
   this.percent = in.readShort();
   if (in.readBoolean()) {
     this.loadAverage = in.readDoubleArray();
   } else {
     this.loadAverage = null;
   }
 }
示例#27
0
 public OsInfo(StreamInput in) throws IOException {
   this.refreshInterval = in.readLong();
   this.availableProcessors = in.readInt();
   this.allocatedProcessors = in.readInt();
   this.name = in.readOptionalString();
   this.arch = in.readOptionalString();
   this.version = in.readOptionalString();
 }
示例#28
0
 @Override
 public void readFrom(StreamInput in) throws IOException {
   int version = in.readVInt(); // version
   uid = new Term(in.readUTF(), in.readUTF());
   if (version >= 1) {
     this.version = in.readLong();
   }
 }
 @Override
 public void readFrom(StreamInput in) throws IOException {
   super.readFrom(in);
   replicationType = ReplicationType.fromId(in.readByte());
   consistencyLevel = WriteConsistencyLevel.fromId(in.readByte());
   timeout = TimeValue.readTimeValue(in);
   index = in.readString();
 }
 @Override
 public void readFrom(StreamInput in) throws IOException {
   super.readFrom(in);
   this.index = in.readOptionalString();
   this.shard = in.readOptionalVInt();
   this.primary = in.readOptionalBoolean();
   this.includeYesDecisions = in.readBoolean();
 }