|
18 | 18 | package org.apache.beam.sdk.extensions.gcp.options; |
19 | 19 |
|
20 | 20 | import static org.junit.Assert.assertEquals; |
| 21 | +import static org.junit.Assert.assertFalse; |
| 22 | +import static org.junit.Assert.assertNotNull; |
21 | 23 | import static org.junit.Assert.assertThrows; |
22 | 24 |
|
| 25 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 26 | +import com.google.cloud.hadoop.gcsio.GoogleCloudStorageReadOptions; |
23 | 27 | import java.util.Collections; |
24 | 28 | import java.util.HashMap; |
25 | 29 | import java.util.Map; |
| 30 | +import org.apache.beam.sdk.options.PipelineOptions; |
26 | 31 | import org.apache.beam.sdk.options.PipelineOptionsFactory; |
27 | 32 | import org.junit.Test; |
28 | 33 | import org.junit.runner.RunWith; |
@@ -75,4 +80,30 @@ public void testEntriesWithErrors() throws Exception { |
75 | 80 | IllegalArgumentException.class, |
76 | 81 | () -> PipelineOptionsFactory.fromArgs(TOO_MANY_ENTRIES_WITH_JOB).as(GcsOptions.class)); |
77 | 82 | } |
| 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 | + } |
78 | 109 | } |
0 commit comments