Skip to content

Commit bcc9968

Browse files
committed
Add a unit test
1 parent b03dd52 commit bcc9968

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

  • sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/options

sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/options/GcsOptionsTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,16 @@
1818
package org.apache.beam.sdk.extensions.gcp.options;
1919

2020
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertFalse;
22+
import static org.junit.Assert.assertNotNull;
2123
import static org.junit.Assert.assertThrows;
2224

25+
import com.fasterxml.jackson.databind.ObjectMapper;
26+
import com.google.cloud.hadoop.gcsio.GoogleCloudStorageReadOptions;
2327
import java.util.Collections;
2428
import java.util.HashMap;
2529
import java.util.Map;
30+
import org.apache.beam.sdk.options.PipelineOptions;
2631
import org.apache.beam.sdk.options.PipelineOptionsFactory;
2732
import org.junit.Test;
2833
import org.junit.runner.RunWith;
@@ -75,4 +80,30 @@ public void testEntriesWithErrors() throws Exception {
7580
IllegalArgumentException.class,
7681
() -> PipelineOptionsFactory.fromArgs(TOO_MANY_ENTRIES_WITH_JOB).as(GcsOptions.class));
7782
}
83+
84+
@Test
85+
public void testGoogleCloudStorageReadOptionsSerialization() throws Exception {
86+
GcsOptions options = PipelineOptionsFactory.as(GcsOptions.class);
87+
GoogleCloudStorageReadOptions readOptions =
88+
GoogleCloudStorageReadOptions.builder()
89+
.setFadvise(GoogleCloudStorageReadOptions.Fadvise.SEQUENTIAL)
90+
.setFastFailOnNotFoundEnabled(false)
91+
.setMinRangeRequestSize(12345L)
92+
.build();
93+
options.setGoogleCloudStorageReadOptions(readOptions);
94+
95+
ObjectMapper mapper = new ObjectMapper();
96+
String serialized = mapper.writeValueAsString(options);
97+
GcsOptions deserialized =
98+
mapper.readValue(serialized, PipelineOptions.class).as(GcsOptions.class);
99+
100+
GoogleCloudStorageReadOptions deserializedReadOptions =
101+
deserialized.getGoogleCloudStorageReadOptions();
102+
103+
assertNotNull(deserializedReadOptions);
104+
assertEquals(
105+
GoogleCloudStorageReadOptions.Fadvise.SEQUENTIAL, deserializedReadOptions.getFadvise());
106+
assertFalse(deserializedReadOptions.isFastFailOnNotFoundEnabled());
107+
assertEquals(12345L, deserializedReadOptions.getMinRangeRequestSize());
108+
}
78109
}

0 commit comments

Comments
 (0)