Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add null check for execution env in sink [DO_NOT_MERGE] #143

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public class BigQuerySink {
private static final Logger LOG = LoggerFactory.getLogger(BigQuerySink.class);

public static Sink get(BigQuerySinkConfig sinkConfig, StreamExecutionEnvironment env) {
if (env == null) {
LOG.error("BigQuerySink requires a valid StreamExecutionEnvironment. Found null.");
throw new IllegalArgumentException("StreamExecutionEnvironment not provided");
}
if (sinkConfig.getDeliveryGuarantee() == DeliveryGuarantee.AT_LEAST_ONCE) {
return new BigQueryDefaultSink(sinkConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.flink.bigquery.sink;

import org.apache.flink.connector.base.DeliveryGuarantee;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import com.google.cloud.flink.bigquery.fakes.StorageClientFaker;
import com.google.cloud.flink.bigquery.sink.serializer.FakeBigQuerySerializer;
Expand All @@ -31,6 +32,8 @@
/** Tests for {@link BigQuerySink}. */
public class BigQuerySinkTest {

StreamExecutionEnvironment env = new StreamExecutionEnvironment();

@Test
public void testGetWithAtLeastOnce() throws IOException {
BigQuerySinkConfig sinkConfig =
Expand All @@ -40,6 +43,18 @@ public void testGetWithAtLeastOnce() throws IOException {
.serializer(new FakeBigQuerySerializer(ByteString.copyFromUtf8("foo")))
.deliveryGuarantee(DeliveryGuarantee.AT_LEAST_ONCE)
.build();
assertNotNull(BigQuerySink.get(sinkConfig, env));
}

@Test(expected = IllegalArgumentException.class)
public void testGetWithNullStreamExecutionEnv() throws IOException {
BigQuerySinkConfig sinkConfig =
BigQuerySinkConfig.newBuilder()
.connectOptions(StorageClientFaker.createConnectOptionsForWrite(null))
.schemaProvider(TestBigQuerySchemas.getSimpleRecordSchema())
.serializer(new FakeBigQuerySerializer(ByteString.copyFromUtf8("foo")))
.deliveryGuarantee(DeliveryGuarantee.NONE)
.build();
assertNotNull(BigQuerySink.get(sinkConfig, null));
}

Expand All @@ -52,7 +67,7 @@ public void testGetWithNoneDeliveryGuarantee() throws IOException {
.serializer(new FakeBigQuerySerializer(ByteString.copyFromUtf8("foo")))
.deliveryGuarantee(DeliveryGuarantee.NONE)
.build();
assertNotNull(BigQuerySink.get(sinkConfig, null));
assertNotNull(BigQuerySink.get(sinkConfig, env));
}

@Test(expected = UnsupportedOperationException.class)
Expand All @@ -64,6 +79,6 @@ public void testExactlyOnceNotSupported() throws IOException {
.serializer(new FakeBigQuerySerializer(ByteString.copyFromUtf8("foo")))
.deliveryGuarantee(DeliveryGuarantee.EXACTLY_ONCE)
.build();
assertNotNull(BigQuerySink.get(sinkConfig, null));
assertNotNull(BigQuerySink.get(sinkConfig, env));
}
}
Loading