Repository: asterixdb
Updated Branches:
  refs/heads/master 246fbde6d -> 79abb7011


Add test cases for alive feed check when connect/disconnect

`connect feed' and `disconnect feed` are not allowed when feed is alive.
Add two test cases to check both exceptions.

Change-Id: Icbcc19da2a9f42bee21b52932ba4f19a0f01aeec
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1664
Sonar-Qube: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Reviewed-by: Steven Jacobs <sjaco...@ucr.edu>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/79abb701
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/79abb701
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/79abb701

Branch: refs/heads/master
Commit: 79abb70110aa83c0f7983868bb6e89a9b8bd3913
Parents: 246fbde
Author: Xikui Wang <xkk...@gmail.com>
Authored: Wed Apr 5 17:31:23 2017 -0700
Committer: Xikui Wang <xkk...@gmail.com>
Committed: Fri Apr 7 10:28:17 2017 -0700

----------------------------------------------------------------------
 .../asterix/app/translator/QueryTranslator.java | 11 ++++++
 .../connect-live-feed.0.ddl.aql                 | 40 +++++++++++++++++++
 .../connect-live-feed.1.update.aql              | 21 ++++++++++
 .../connect-live-feed.2.sleep.aql               | 19 +++++++++
 .../connect-live-feed.3.update.aql              | 21 ++++++++++
 .../disconnect-live-feed.0.ddl.aql              | 41 ++++++++++++++++++++
 .../disconnect-live-feed.1.update.aql           | 21 ++++++++++
 .../disconnect-live-feed.2.sleep.aql            | 19 +++++++++
 .../disconnect-live-feed.3.update.aql           | 21 ++++++++++
 .../src/test/resources/runtimets/testsuite.xml  | 12 ++++++
 .../asterix/common/exceptions/ErrorCode.java    |  2 +-
 .../main/resources/asx_errormsg/en.properties   |  2 +-
 12 files changed, 228 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79abb701/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
index 88d07e4..cb59f5c 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
@@ -60,6 +60,7 @@ import org.apache.asterix.common.config.GlobalConfig;
 import org.apache.asterix.common.context.IStorageComponentProvider;
 import org.apache.asterix.common.exceptions.ACIDException;
 import org.apache.asterix.common.exceptions.CompilationException;
+import org.apache.asterix.common.exceptions.ErrorCode;
 import org.apache.asterix.common.functions.FunctionSignature;
 import org.apache.asterix.common.metadata.IDataset;
 import org.apache.asterix.common.utils.JobUtils;
@@ -2104,6 +2105,11 @@ public class QueryTranslator extends 
AbstractLangTranslator implements IStatemen
         String policyName = cfs.getPolicy();
         MetadataTransactionContext mdTxnCtx = 
MetadataManager.INSTANCE.beginTransaction();
         metadataProvider.setMetadataTxnContext(mdTxnCtx);
+        // Check whether feed is alive
+        if (ActiveJobNotificationHandler.INSTANCE
+                .getActiveEntityListener(new EntityId(Feed.EXTENSION_NAME, 
dataverseName, feedName)) != null) {
+            throw new 
CompilationException(ErrorCode.FEED_CHANGE_FEED_CONNECTIVITY_ON_ALIVE_FEED, 
feedName);
+        }
         // Transaction handling
         
MetadataLockManager.INSTANCE.connectFeedBegin(metadataProvider.getLocks(), 
dataverseName,
                 dataverseName + "." + datasetName, dataverseName + "." + 
feedName);
@@ -2139,6 +2145,11 @@ public class QueryTranslator extends 
AbstractLangTranslator implements IStatemen
         String feedName = cfs.getFeedName().getValue();
         MetadataTransactionContext mdTxnCtx = 
MetadataManager.INSTANCE.beginTransaction();
         metadataProvider.setMetadataTxnContext(mdTxnCtx);
+        // Check whether feed is alive
+        if (ActiveJobNotificationHandler.INSTANCE
+                .getActiveEntityListener(new EntityId(Feed.EXTENSION_NAME, 
dataverseName, feedName)) != null) {
+            throw new 
CompilationException(ErrorCode.FEED_CHANGE_FEED_CONNECTIVITY_ON_ALIVE_FEED, 
feedName);
+        }
         
MetadataLockManager.INSTANCE.disconnectFeedBegin(metadataProvider.getLocks(), 
dataverseName,
                 dataverseName + "." + datasetName, dataverseName + "." + 
cfs.getFeedName());
         try {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79abb701/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.0.ddl.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.0.ddl.aql
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.0.ddl.aql
new file mode 100644
index 0000000..47bee4d
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.0.ddl.aql
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+drop dataverse new_experiments if exists;
+create dataverse new_experiments;
+use dataverse new_experiments;
+
+create type TweetMessageType as closed {
+ tweetid: string,
+ tweetid-copy:string
+}
+
+create dataset Tweets1(TweetMessageType) primary key tweetid;
+create dataset Tweets2(TweetMessageType) primary key tweetid;
+
+create feed TweetFeed using socket_adapter
+(
+ ("sockets"="127.0.0.1:10001"),
+ ("address-type"="IP"),
+ ("type-name"="TweetMessageType"),
+ ("format"="adm")
+);
+
+connect feed TweetFeed to dataset Tweets1;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79abb701/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.1.update.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.1.update.aql
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.1.update.aql
new file mode 100644
index 0000000..4f3cb19
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.1.update.aql
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+use dataverse new_experiments;
+start feed TweetFeed;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79abb701/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.2.sleep.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.2.sleep.aql
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.2.sleep.aql
new file mode 100644
index 0000000..5af9639
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.2.sleep.aql
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+1000
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79abb701/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.3.update.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.3.update.aql
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.3.update.aql
new file mode 100644
index 0000000..4b7aaa4
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/connect-live-feed/connect-live-feed.3.update.aql
@@ -0,0 +1,21 @@
+/*
+ * 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.1
+ */
+
+use dataverse new_experiments;
+connect feed TweetFeed to dataset Tweets2;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79abb701/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.0.ddl.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.0.ddl.aql
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.0.ddl.aql
new file mode 100644
index 0000000..00fb12d
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.0.ddl.aql
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+drop dataverse new_experiments if exists;
+create dataverse new_experiments;
+use dataverse new_experiments;
+
+create type TweetMessageType as closed {
+ tweetid: string,
+ tweetid-copy:string
+}
+
+create dataset Tweets1(TweetMessageType) primary key tweetid;
+create dataset Tweets2(TweetMessageType) primary key tweetid;
+
+create feed TweetFeed using socket_adapter
+(
+ ("sockets"="127.0.0.1:10001"),
+ ("address-type"="IP"),
+ ("type-name"="TweetMessageType"),
+ ("format"="adm")
+);
+
+connect feed TweetFeed to dataset Tweets1;
+connect feed TweetFeed to dataset Tweets2;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79abb701/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.1.update.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.1.update.aql
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.1.update.aql
new file mode 100644
index 0000000..4f3cb19
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.1.update.aql
@@ -0,0 +1,21 @@
+/*
+ * 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.
+ */
+
+use dataverse new_experiments;
+start feed TweetFeed;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79abb701/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.2.sleep.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.2.sleep.aql
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.2.sleep.aql
new file mode 100644
index 0000000..5af9639
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.2.sleep.aql
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+1000
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79abb701/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.3.update.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.3.update.aql
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.3.update.aql
new file mode 100644
index 0000000..0095d89
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/feeds/disconnect-live-feed/disconnect-live-feed.3.update.aql
@@ -0,0 +1,21 @@
+/*
+ * 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.1
+ */
+
+use dataverse new_experiments;
+disconnect feed TweetFeed from dataset Tweets1;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79abb701/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml 
b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
index 122a4c6..7a486b7 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -254,6 +254,18 @@
         <output-dir compare="Text">connect-feed-with-aql-function</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="feeds">
+      <compilation-unit name="disconnect-live-feed">
+        <output-dir compare="Text">disconnect-live-feed</output-dir>
+        <expected-error>This operation cannot be done when 
Feed</expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="feeds">
+      <compilation-unit name="connect-live-feed">
+        <output-dir compare="Text">connect-live-feed</output-dir>
+        <expected-error>This operation cannot be done when 
Feed</expected-error>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="upsert">
     <test-case FilePath="upsert">

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79abb701/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
index f521801..9de9dde 100644
--- 
a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
+++ 
b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java
@@ -116,7 +116,7 @@ public class ErrorCode {
     public static final int PARSER_HIVE_NULL_VALUE_IN_LIST = 3017;
     public static final int 
INPUT_RECORD_RECORD_WITH_METADATA_AND_PK_NULL_IN_NON_OPTIONAL = 3018;
     public static final int 
INPUT_RECORD_RECORD_WITH_METADATA_AND_PK_CANNT_GET_PKEY = 3019;
-    public static final int 
FEED_MANAGEMENT_FEED_EVENT_LISTENER_FEED_JOINT_REGISTERED = 3020;
+    public static final int FEED_CHANGE_FEED_CONNECTIVITY_ON_ALIVE_FEED = 3020;
     public static final int 
FEED_MANAGEMENT_FEED_EVENT_REGISTER_INTAKE_JOB_FAIL = 3021;
     public static final int PROVIDER_DATAFLOW_CONTROLLER_UNKNOWN_DATA_SOURCE = 
3022;
     public static final int 
PROVIDER_DATASOURCE_FACTORY_UNKNOWN_INPUT_STREAM_FACTORY = 3023;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/79abb701/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties 
b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
index 9e1ad76..b6423f6 100644
--- a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
+++ b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties
@@ -102,7 +102,7 @@
 3017 = can't parse hive list with null values
 3018 = Field %1$s of meta record is not an optional type so it cannot accept 
null value.
 3019 = Can't get PK from record part
-3020 = Feed joint %1$s already registered
+3020 = This operation cannot be done when Feed %1$s is alive.
 3021 = Could not register feed intake job [%1$s] for feed  %2$s
 3022 = Unknown data source type: %1$s
 3023 = Unknown input stream factory: %1$s

Reply via email to