[ASTERIXDB-1950][ING][API] Add IT for ActiveEntity stats

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
1. Added one IT for feed stats request API.
2. Minor tweak to the API to produce proper JSON.

Change-Id: Iecbe00bcd93dcfd4ef9b800ce5719e85ae2cfd42
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1862
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
BAD: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: abdullah alamoudi <bamousaa@gmail.com>
diff --git a/asterixdb/asterix-app/data/twitter/mixed_tweets.adm b/asterixdb/asterix-app/data/twitter/mixed_tweets.adm
new file mode 100644
index 0000000..6529787
--- /dev/null
+++ b/asterixdb/asterix-app/data/twitter/mixed_tweets.adm
@@ -0,0 +1,13 @@
+{"tweetid":"1","tweetid-copy":"1","user":{"screen-name":"RollandEckhardstein#211","lang":"en","friends_count":3657079,"statuses_count":268,"name":"Rolland Eckhardstein","followers_count":3311368},"sender-location":point("42.13,80.43"),"send-time":datetime("2005-12-05T21:06:41"),"send-time-copy":datetime("2005-12-05T21:06:41"),"referred-topics":{{"samsung","plan"}},"message-text":" love samsung the plan is amazing"}
+{"tweetid":"2","tweetid-copy":"2","user":{"screen-name":"RollandEckhardstein#211","lang":"en","friends_count":3657079,"statuses_count":268,"name":"David Eckhardstein","followers_count":3311368},"sender-location":point("28.86,70.44"),"send-time":datetime("2007-08-15T06:44:17"),"send-time-copy":datetime("2007-08-15T06:44:17"),"referred-topics":{{"sprint","voice-clarity"}},"message-text":" like sprint its voice-clarity is mind-blowing"}
+{"tweetid":"3","tweetid-copy":"3","user":{"screen-name":"RollandEckhard#500","lang":"en","friends_count":3657079,"statuses_count":268,"name":"Rolland Hetfield","followers_count":3311368},"sender-location":point("39.84,86.48"),"send-time":datetime("2008-12-24T00:07:04"),"send-time-copy":datetime("2008-12-24T00:07:04"),"referred-topics":{{"verizon","voice-command"}},"message-text":" can't stand verizon its voice-command is terrible:("}
+{"tweetid":"4","tweetid-copy":"4","user":{"screen-name":"RollandEckhardstein#221","lang":"en","friends_count":3657079,"statuses_count":268,"name":"Rolland Eckhardstinz","followers_count":3311368},"sender-location":point("27.67,87.32"),"send-time":datetime("2007-02-05T16:39:13"),"send-time-copy":datetime("2007-02-05T16:39:13"),"referred-topics":{{"t-mobile","customer-service"}},"message-text":" love t-mobile its customer-service is mind-blowing"}
+{"tweetid":"5","tweetid-copy":"5","user":{"screen-name":"RollandEcstein#211","lang":"en","friends_count":3657079,"statuses_count":268,"name":"Rolland Eckhardst","followers_count":3311368},"sender-location":point("27.3,92.77"),"send-time":datetime("2010-09-12T06:15:28"),"send-time-copy":datetime("2010-09-12T06:15:28"),"referred-topics":{{"t-mobile","customization"}},"message-text":" like t-mobile the customization is amazing:)"}
+{"tweetid":"6","tweetid-copy":"6","user":{"screen-name":"Rollkhardstein#211","lang":"en","friends_count":3657079,"statuses_count":268,"name":"Kirk Hammette ","followers_count":3311368},"sender-location":point("45.62,84.78"),"send-time":datetime("2012-01-23T06:23:13"),"send-time-copy":datetime("2012-01-23T06:23:13"),"referred-topics":{{"iphone","network"}},"message-text":" like iphone its network is awesome:)"}
+{ "create_at": datetime("2012-05-01T09:15:07.000Z"), "id": 197358499422928896, "text": "I hate writing document", "in_reply_to_status": -1, "in_reply_to_user": -1, "favorite_count": -1, "coordinate": point("-81.6430449, 38.3092672"), "retweet_count": 0, "lang": "null", "is_retweet": false, "hashtags": {{ "hate", "document" }}, "user_mentions": null, "user": { "id": 331998689, "name": "ImAGlenardenNigga", "screen_name": "WhiteBoyTurntUp", "lang": "en", "location": "Glenarden D $M$ V ", "create_at": date("2011-07-08"), "description": "#TeamNAS #TeamTatted #TeamTakin #TeamLightSkin #TeamRollUp #TeamGDHU #TeamGlenarden #Follow My Folk's @EfffYou_PayMe & Go Follow My Short Stuff @_Chinkyy ", "followers_count": 1629, "friends_count": 1542, "statues_count": 40754 }, "place": { "country": "United States", "country_code": "United States", "full_name": "Charleston, WV", "id": "44439f1538ac3ca0", "name": "Charleston", "place_type": "city", "bounding_box": rectangle("-81.727777,38.281139 -81.559673,38.405759") }, "geo_tag": { "stateID": 54, "stateName": "West Virgnia", "countyID": 54039, "countyName": "Kanawha", "cityID": 5414600, "cityName": "Charleston" } }
+{ "create_at": datetime("2012-05-01T09:15:07.000Z"), "id": 197358499422928891, "text": "I hate writing document", "in_reply_to_status": -1, "in_reply_to_user": -1, "favorite_count": -1, "coordinate": point("-81.6430449, 38.3092672"), "retweet_count": 0, "lang": "null", "is_retweet": false, "hashtags": {{ "hate", "document" }}, "user_mentions": null, "user": { "id": 331998689, "name": "ImAGlenardenNigga", "screen_name": "WhiteBoyTurntUp", "lang": "en", "location": "Glenarden D $M$ V ", "create_at": date("2011-07-08"), "description": "#TeamNAS #TeamTatted #TeamTakin #TeamLightSkin #TeamRollUp #TeamGDHU #TeamGlenarden #Follow My Folk's @EfffYou_PayMe & Go Follow My Short Stuff @_Chinkyy ", "followers_count": 1629, "friends_count": 1542, "statues_count": 40754 }, "place": { "country": "United States", "country_code": "United States", "full_name": "Charleston, WV", "id": "44439f1538ac3ca0", "name": "Charleston", "place_type": "city", "bounding_box": rectangle("-81.727777,38.281139 -81.559673,38.405759") }, "geo_tag": { "stateID": 54, "stateName": "West Virgnia", "countyID": 54039, "countyName": "Kanawha", "cityID": 5414600, "cityName": "Charleston" } }
+{ "create_at": datetime("2012-05-01T09:15:07.000Z"), "id": 197358499422928892, "text": "I hate writing document", "in_reply_to_status": -1, "in_reply_to_user": -1, "favorite_count": -1, "coordinate": point("-81.6430449, 38.3092672"), "retweet_count": 0, "lang": "null", "is_retweet": false, "hashtags": {{ "hate", "document" }}, "user_mentions": null, "user": { "id": 331998689, "name": "ImAGlenardenNigga", "screen_name": "WhiteBoyTurntUp", "lang": "en", "location": "Glenarden D $M$ V ", "create_at": date("2011-07-08"), "description": "#TeamNAS #TeamTatted #TeamTakin #TeamLightSkin #TeamRollUp #TeamGDHU #TeamGlenarden #Follow My Folk's @EfffYou_PayMe & Go Follow My Short Stuff @_Chinkyy ", "followers_count": 1629, "friends_count": 1542, "statues_count": 40754 }, "place": { "country": "United States", "country_code": "United States", "full_name": "Charleston, WV", "id": "44439f1538ac3ca0", "name": "Charleston", "place_type": "city", "bounding_box": rectangle("-81.727777,38.281139 -81.559673,38.405759") }, "geo_tag": { "stateID": 54, "stateName": "West Virgnia", "countyID": 54039, "countyName": "Kanawha", "cityID": 5414600, "cityName": "Charleston" } }
+{"tweetid":"7","tweetid-copy":"7","user":{"screen-name":"andEckhardstein#211","lang":"en","friends_count":3657079,"statuses_count":268,"name":"Rolland khardstein","followers_count":3311368},"sender-location":point("44.12,81.46"),"send-time":datetime("2012-02-17T17:30:26"),"send-time-copy":datetime("2012-02-17T17:30:26"),"referred-topics":{{"t-mobile","network"}},"message-text":" hate t-mobile the network is bad"}
+{"tweetid":"8","tweetid-copy":"8","user":{"screen-name":"Rolltein#211","lang":"en","friends_count":3657079,"statuses_count":268,"name":"Ron Eckhardstein","followers_count":3311368},"sender-location":point("36.86,90.71"),"send-time":datetime("2009-03-12T13:18:04"),"send-time-copy":datetime("2009-03-12T13:18:04"),"referred-topics":{{"at&t","touch-screen"}},"message-text":" dislike at&t its touch-screen is OMG"}
+{"tweetid":"9","tweetid-copy":"9","user":{"screen-name":"Roldstein#211","lang":"en","friends_count":3657079,"statuses_count":268,"name":"Rolland Eckdstein","followers_count":3311368},"sender-location":point("29.07,97.05"),"send-time":datetime("2012-08-15T20:19:46"),"send-time-copy":datetime("2012-08-15T20:19:46"),"referred-topics":{{"verizon","speed"}},"message-text":" hate verizon its speed is bad"}
+{"tweetid":"10","tweetid-copy":"10","user":{"screen-name":"Rolldstein#211","lang":"en","friends_count":3657079,"statuses_count":268,"name":"Rolland Eckhardstful","followers_count":3311368},"sender-location":point("46.94,93.98"),"send-time":datetime("2011-04-07T14:08:46"),"send-time-copy":datetime("2011-04-07T14:08:46"),"referred-topics":{{"t-mobile","signal"}},"message-text":" like t-mobile the signal is good"}
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ActiveStatsApiServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ActiveStatsApiServlet.java
index e02f09b..593faa6 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ActiveStatsApiServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/ActiveStatsApiServlet.java
@@ -21,7 +21,10 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.concurrent.ConcurrentMap;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
+import io.netty.handler.codec.http.HttpResponseStatus;
 import org.apache.asterix.active.ActiveLifecycleListener;
 import org.apache.asterix.active.IActiveEntityEventsListener;
 import org.apache.asterix.common.dataflow.ICcApplicationContext;
@@ -37,6 +40,7 @@
 
 public class ActiveStatsApiServlet extends AbstractServlet {
 
+    private static final Logger LOGGER = Logger.getLogger(ActiveStatsApiServlet.class.getName());
     private static final int DEFAULT_EXPIRE_TIME = 2000;
     private final ActiveLifecycleListener activeLifecycleListener;
 
@@ -66,21 +70,26 @@
         ObjectMapper om = new ObjectMapper();
         om.enable(SerializationFeature.INDENT_OUTPUT);
         ObjectNode resNode = om.createObjectNode();
-
-        if (localPath.length() == 0 || localPath.length() == 1) {
-            expireTime = DEFAULT_EXPIRE_TIME;
-        } else {
-            expireTime = Integer.valueOf(localPath.substring(1));
-        }
-        long currentTime = System.currentTimeMillis();
-        for (int iter1 = 0; iter1 < listeners.length; iter1++) {
-            resNode.putPOJO(listeners[iter1].getEntityId().toString(),
-                    constructNode(om, listeners[iter1], currentTime, expireTime));
-        }
-
-        // Construct Response
         PrintWriter responseWriter = response.writer();
-        responseWriter.write(om.writerWithDefaultPrettyPrinter().writeValueAsString(resNode));
+        try {
+            response.setStatus(HttpResponseStatus.OK);
+            if (localPath.length() == 0 || localPath.length() == 1) {
+                expireTime = DEFAULT_EXPIRE_TIME;
+            } else {
+                expireTime = Integer.valueOf(localPath.substring(1));
+            }
+            long currentTime = System.currentTimeMillis();
+            for (int iter1 = 0; iter1 < listeners.length; iter1++) {
+                resNode.putPOJO(listeners[iter1].getEntityId().toString(),
+                        constructNode(om, listeners[iter1], currentTime, expireTime));
+            }
+            // Construct Response
+            responseWriter.write(om.writerWithDefaultPrettyPrinter().writeValueAsString(resNode));
+        } catch (Exception e) {
+            LOGGER.log(Level.INFO, "exception thrown for " + request, e);
+            response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
+            responseWriter.write(e.toString());
+        }
         responseWriter.flush();
     }
 }
diff --git a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/active/ActiveStatsTest.java b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/active/ActiveStatsTest.java
index e932006..956d111 100644
--- a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/active/ActiveStatsTest.java
+++ b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/active/ActiveStatsTest.java
@@ -52,7 +52,7 @@
 public class ActiveStatsTest {
 
     protected boolean cleanUp = true;
-    private static String EXPECTED_STATS = "Mock stats";
+    private static String EXPECTED_STATS = "\"Mock stats\"";
 
     @Before
     public void setUp() throws Exception {
@@ -97,12 +97,12 @@
 
         // Check init stats
         requestedStats = eventsListener.getStats();
-        Assert.assertTrue(requestedStats.equals("N/A"));
+        Assert.assertTrue(requestedStats.contains("N/A"));
 
         // Update stats of not-started job
         eventsListener.refreshStats(1000);
         requestedStats = eventsListener.getStats();
-        Assert.assertTrue(requestedStats.equals("N/A"));
+        Assert.assertTrue(requestedStats.contains("N/A"));
         WaitForStateSubscriber startingSubscriber = new WaitForStateSubscriber(eventsListener, ActivityState.STARTING);
         eventsListener.subscribe(startingSubscriber);
         // Update stats of created/started job without joined partition
@@ -111,7 +111,8 @@
         startingSubscriber.sync();
         eventsListener.refreshStats(1000);
         requestedStats = eventsListener.getStats();
-        Assert.assertTrue(requestedStats.equals("N/A"));
+        Assert.assertTrue(requestedStats.contains("N/A"));
+
         // Fake partition message and notify eventListener
         WaitForStateSubscriber startedSubscriber = new WaitForStateSubscriber(eventsListener, ActivityState.STARTED);
         eventsListener.subscribe(startedSubscriber);
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/api.xml b/asterixdb/asterix-app/src/test/resources/runtimets/api.xml
index 372aa47..b686482 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/api.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/api.xml
@@ -113,5 +113,10 @@
         <expected-error>HTTP/1.1 400 Bad Request</expected-error>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="api">
+      <compilation-unit name="feed-stats">
+        <output-dir compare="Text">feed-stats</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
 </test-suite>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.1.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.1.ddl.aql
new file mode 100644
index 0000000..8089d15
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.1.ddl.aql
@@ -0,0 +1,52 @@
+/*
+ * 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 experiments if exists;
+create dataverse experiments;
+use dataverse experiments;
+
+create type TwitterUserType as closed {
+    screen-name: string,
+    lang: string,
+    friends_count: int32,
+    statuses_count: int32,
+    name: string,
+    followers_count: int32
+}
+
+create type TweetMessageType as closed {
+    tweetid: string,
+    tweetid-copy:string,
+    user: TwitterUserType,
+    sender-location: point,
+    send-time: datetime,
+    send-time-copy:datetime,
+    referred-topics: {{ string }},
+    message-text: 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")
+);
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.2.update.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.2.update.aql
new file mode 100644
index 0000000..e056a87
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.2.update.aql
@@ -0,0 +1,26 @@
+/*
+ * 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 experiments;
+set wait-for-completion-feed "false";
+
+connect feed TweetFeed to dataset Tweets1;
+connect feed TweetFeed to dataset Tweets2;
+
+start feed TweetFeed;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.3.server.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.3.server.aql
new file mode 100644
index 0000000..27b9185
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.3.server.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.
+ */
+start client 10001 file-client 127.0.0.1 ../asterix-app/data/twitter/mixed_tweets.adm 500 50 1000
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.4.sleep.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.4.sleep.aql
new file mode 100644
index 0000000..6559ae8
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.4.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.
+ */
+2000
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.5.get.http b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.5.get.http
new file mode 100644
index 0000000..7c8f995
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.5.get.http
@@ -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.
+ */
+/admin/active
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.6.update.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.6.update.aql
new file mode 100644
index 0000000..2e7268e
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.6.update.aql
@@ -0,0 +1,22 @@
+/*
+ * 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 experiments;
+stop feed TweetFeed;
+disconnect feed TweetFeed from dataset Tweets1;
+disconnect feed TweetFeed from dataset Tweets2;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.7.server.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.7.server.aql
new file mode 100644
index 0000000..c3ba795
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.7.server.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.
+ */
+stop 10001
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.8.ddl.aql b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.8.ddl.aql
new file mode 100644
index 0000000..e3097c8
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries/api/feed-stats/feed-stats.8.ddl.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 experiments;
+drop dataverse experiments;
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/api/feed-stats/feed-stats.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/feed-stats/feed-stats.1.adm
new file mode 100644
index 0000000..d0b0ea0
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/api/feed-stats/feed-stats.1.adm
@@ -0,0 +1,11 @@
+{
+  "experiments.TweetFeed(Feed)" : {
+    "Stats" : [ {
+      "adapter-stats" : {
+        "incoming-records-count" : 13,
+        "failed-at-parser-records-count" : 3
+      },
+      "executor-restart-times" : 0
+    } ]
+  }
+}
\ No newline at end of file
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/feed/management/ActiveEntityEventsListener.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/feed/management/ActiveEntityEventsListener.java
index 409c297..3216bfe 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/feed/management/ActiveEntityEventsListener.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/feed/management/ActiveEntityEventsListener.java
@@ -79,10 +79,10 @@
         this.entityId = entityId;
         this.datasets = datasets;
         this.state = ActivityState.STOPPED;
-        this.statsTimestamp = Long.MIN_VALUE;
+        this.statsTimestamp = -1;
         this.statsRequestState = RequestState.INIT;
         this.statsUpdatedEvent = new ActiveEvent(null, Kind.STATS_UPDATED, entityId);
-        this.stats = "N/A";
+        this.stats = "{\"Stats\":\"N/A\"}";
         this.runtimeName = runtimeName;
         this.locations = locations;
         this.numRegistered = 0;
@@ -180,10 +180,9 @@
 
     public String formatStats(List<String> responses) {
         StringBuilder strBuilder = new StringBuilder();
-        strBuilder.append("{" + "\"EntityId\": \"" + entityId + "\", ");
-        strBuilder.append("\"Stats\": [").append("\"" + responses.get(0) + "\"");
+        strBuilder.append("{\"Stats\": [").append(responses.get(0));
         for (int i = 1; i < responses.size(); i++) {
-            strBuilder.append(", ").append("\"" + responses.get(i) + "\"");
+            strBuilder.append(", ").append(responses.get(i));
         }
         strBuilder.append("]}");
         return strBuilder.toString();