SerializablePipelineOptions implements Serializable { public PipelineOptions get() { return options; } SerializablePipelineOptions(PipelineOptions options);  SerializablePipelineOptions(String json); PipelineOptions get(); @Override String toString(); @Override boolean equals(@Nullable Object o); @Override int hashCode();  }
@Test public void testSerializationAndDeserialization() throws Exception { PipelineOptions options = PipelineOptionsFactory.fromArgs("--foo=testValue", "--ignoredField=overridden") .as(MyOptions.class); SerializablePipelineOptions serializableOptions = new SerializablePipelineOptions(options); assertEquals("testValue", serializableOptions.get().as(MyOptions.class).getFoo()); assertEquals("overridden", serializableOptions.get().as(MyOptions.class).getIgnoredField()); SerializablePipelineOptions copy = SerializableUtils.clone(serializableOptions); assertEquals("testValue", copy.get().as(MyOptions.class).getFoo()); assertEquals("not overridden", copy.get().as(MyOptions.class).getIgnoredField()); }
@Test public void testIndependence() throws Exception { SerializablePipelineOptions first = new SerializablePipelineOptions( PipelineOptionsFactory.fromArgs("--foo=first").as(MyOptions.class)); SerializablePipelineOptions firstCopy = SerializableUtils.clone(first); SerializablePipelineOptions second = new SerializablePipelineOptions( PipelineOptionsFactory.fromArgs("--foo=second").as(MyOptions.class)); SerializablePipelineOptions secondCopy = SerializableUtils.clone(second); assertEquals("first", first.get().as(MyOptions.class).getFoo()); assertEquals("first", firstCopy.get().as(MyOptions.class).getFoo()); assertEquals("second", second.get().as(MyOptions.class).getFoo()); assertEquals("second", secondCopy.get().as(MyOptions.class).getFoo()); first.get().as(MyOptions.class).setFoo("new first"); firstCopy.get().as(MyOptions.class).setFoo("new firstCopy"); second.get().as(MyOptions.class).setFoo("new second"); secondCopy.get().as(MyOptions.class).setFoo("new secondCopy"); assertEquals("new first", first.get().as(MyOptions.class).getFoo()); assertEquals("new firstCopy", firstCopy.get().as(MyOptions.class).getFoo()); assertEquals("new second", second.get().as(MyOptions.class).getFoo()); assertEquals("new secondCopy", secondCopy.get().as(MyOptions.class).getFoo()); }