You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by jo...@apache.org on 2018/08/03 20:38:21 UTC

[incubator-druid] branch master updated: validate baseDataSource non-empty string in DerivativeDataSourceMetad… (#6072)

This is an automated email from the ASF dual-hosted git repository.

jonwei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-druid.git


The following commit(s) were added to refs/heads/master by this push:
     new 914058f  validate baseDataSource non-empty string in DerivativeDataSourceMetad… (#6072)
914058f is described below

commit 914058f28840e466c7fc827d63da1eb608cc8060
Author: chengchengpei <ch...@users.noreply.github.com>
AuthorDate: Fri Aug 3 16:38:18 2018 -0400

    validate baseDataSource non-empty string in DerivativeDataSourceMetad… (#6072)
    
    * validate baseDataSource non-empty string in DerivativeDataSourceMetadata; added a test
    
    * added another test for validating null baseDataSource
    
    * restored the arguments check order
---
 .../DerivativeDataSourceMetadata.java              |  5 +-
 .../DerivativeDataSourceMetadataTest.java          | 61 ++++++++++++++++++++++
 2 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/extensions-contrib/materialized-view-maintenance/src/main/java/io/druid/indexing/materializedview/DerivativeDataSourceMetadata.java b/extensions-contrib/materialized-view-maintenance/src/main/java/io/druid/indexing/materializedview/DerivativeDataSourceMetadata.java
index ed102e3..3a82672 100644
--- a/extensions-contrib/materialized-view-maintenance/src/main/java/io/druid/indexing/materializedview/DerivativeDataSourceMetadata.java
+++ b/extensions-contrib/materialized-view-maintenance/src/main/java/io/druid/indexing/materializedview/DerivativeDataSourceMetadata.java
@@ -23,6 +23,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Sets;
+import com.google.common.base.Strings;
 import io.druid.indexing.overlord.DataSourceMetadata;
 
 import java.util.Objects;
@@ -41,7 +42,9 @@ public class DerivativeDataSourceMetadata implements DataSourceMetadata
       @JsonProperty("metrics") Set<String> metrics
   )
   {
-    this.baseDataSource = Preconditions.checkNotNull(baseDataSource, "baseDataSource cannot be null. This is not a valid DerivativeDataSourceMetadata.");
+    Preconditions.checkArgument(!Strings.isNullOrEmpty(baseDataSource), "baseDataSource cannot be null or empty. Please provide a baseDataSource.");
+    this.baseDataSource = baseDataSource;
+
     this.dimensions = Preconditions.checkNotNull(dimensions, "dimensions cannot be null. This is not a valid DerivativeDataSourceMetadata.");
     this.metrics = Preconditions.checkNotNull(metrics, "metrics cannot be null. This is not a valid DerivativeDataSourceMetadata.");
   }
diff --git a/extensions-contrib/materialized-view-maintenance/src/test/java/io/druid/indexing/materializedview/DerivativeDataSourceMetadataTest.java b/extensions-contrib/materialized-view-maintenance/src/test/java/io/druid/indexing/materializedview/DerivativeDataSourceMetadataTest.java
new file mode 100644
index 0000000..d62ea38
--- /dev/null
+++ b/extensions-contrib/materialized-view-maintenance/src/test/java/io/druid/indexing/materializedview/DerivativeDataSourceMetadataTest.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package io.druid.indexing.materializedview;
+
+import com.google.common.collect.Sets;
+import org.hamcrest.CoreMatchers;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.util.Set;
+
+
+public class DerivativeDataSourceMetadataTest
+{
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
+  @Test
+  public void testEmptyBaseDataSource() throws Exception
+  {
+    expectedException.expect(CoreMatchers.instanceOf(IllegalArgumentException.class));
+    expectedException.expectMessage(
+        "baseDataSource cannot be null or empty. Please provide a baseDataSource."
+    );
+    String baseDataSource = "";
+    Set<String> dims = Sets.newHashSet("dim1", "dim2", "dim3");
+    Set<String> metrics = Sets.newHashSet("cost");
+    DerivativeDataSourceMetadata metadata = new DerivativeDataSourceMetadata(baseDataSource, dims, metrics);
+  }
+
+  @Test
+  public void testNullBaseDataSource() throws Exception
+  {
+    expectedException.expect(CoreMatchers.instanceOf(IllegalArgumentException.class));
+    expectedException.expectMessage(
+        "baseDataSource cannot be null or empty. Please provide a baseDataSource."
+    );
+    String baseDataSource = null;
+    Set<String> dims = Sets.newHashSet("dim1", "dim2", "dim3");
+    Set<String> metrics = Sets.newHashSet("cost");
+    DerivativeDataSourceMetadata metadata = new DerivativeDataSourceMetadata(baseDataSource, dims, metrics);
+  }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org