/** * Since custom metadata can be loaded by a plugin class loader that resides in a sub-node, we need to * marshal this object into something the tribe node can work with */ private MetaData.Custom marshal(MetaData.Custom custom) { try (BytesStreamOutput bytesStreamOutput = new BytesStreamOutput()){ bytesStreamOutput.writeNamedWriteable(custom); try(StreamInput input = bytesStreamOutput.bytes().streamInput()) { StreamInput namedInput = new NamedWriteableAwareStreamInput(input, namedWriteableRegistry); MetaData.Custom marshaled = namedInput.readNamedWriteable(MetaData.Custom.class); return marshaled; } } catch (IOException ex) { throw new IllegalStateException("cannot marshal object with type " + custom.getWriteableName() + " to tribe node"); } } }
/** * Since custom metadata can be loaded by a plugin class loader that resides in a sub-node, we need to * marshal this object into something the tribe node can work with */ private MetaData.Custom marshal(MetaData.Custom custom) { try (BytesStreamOutput bytesStreamOutput = new BytesStreamOutput()){ bytesStreamOutput.writeNamedWriteable(custom); try(StreamInput input = bytesStreamOutput.bytes().streamInput()) { StreamInput namedInput = new NamedWriteableAwareStreamInput(input, namedWriteableRegistry); MetaData.Custom marshaled = namedInput.readNamedWriteable(MetaData.Custom.class); return marshaled; } } catch (IOException ex) { throw new IllegalStateException("cannot marshal object with type " + custom.getWriteableName() + " to tribe node"); } } }
/** * Serialize the given query builder and asserts that both are equal */ protected static QueryBuilder assertSerialization(QueryBuilder testQuery, Version version) throws IOException { try (BytesStreamOutput output = new BytesStreamOutput()) { output.setVersion(version); output.writeNamedWriteable(testQuery); try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), serviceHolder.namedWriteableRegistry)) { in.setVersion(version); QueryBuilder deserializedQuery = in.readNamedWriteable(QueryBuilder.class); assertEquals(testQuery, deserializedQuery); assertEquals(testQuery.hashCode(), deserializedQuery.hashCode()); assertNotSame(testQuery, deserializedQuery); return deserializedQuery; } } }
/** * Test serialization and deserialization of the test AggregatorFactory. */ public void testSerialization() throws IOException { AB testAgg = createTestAggregatorBuilder(); try (BytesStreamOutput output = new BytesStreamOutput()) { output.writeNamedWriteable(testAgg); try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) { AggregationBuilder deserialized = in.readNamedWriteable(AggregationBuilder.class); assertEquals(testAgg, deserialized); assertEquals(testAgg.hashCode(), deserialized.hashCode()); assertNotSame(testAgg, deserialized); } } }