You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ga...@apache.org on 2015/12/01 04:39:39 UTC
[6/7] stratos git commit: Adding ThriftStatisticsPublisherTest and
updating ThriftStatisticsPublisher and ThiriftClientConfigParserTest
Adding ThriftStatisticsPublisherTest and updating ThriftStatisticsPublisher and ThiriftClientConfigParserTest
Project: http://git-wip-us.apache.org/repos/asf/stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/5435bffd
Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/5435bffd
Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/5435bffd
Branch: refs/heads/stratos-4.1.x
Commit: 5435bffd21f21aa26a61f6cf3df345af453e20f6
Parents: 85036eb
Author: Thanuja <th...@wso2.com>
Authored: Mon Nov 30 16:12:45 2015 +0530
Committer: gayangunarathne <ga...@wso2.com>
Committed: Tue Dec 1 08:57:55 2015 +0530
----------------------------------------------------------------------
.../publisher/ThriftStatisticsPublisher.java | 20 +++---
.../test/ThriftClientConfigParserTest.java | 73 +++++++++++---------
.../test/ThriftStatisticsPublisherTest.java | 60 ++++++++++++++++
.../src/test/resources/thrift-client-config.xml | 53 ++++++++------
4 files changed, 142 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/stratos/blob/5435bffd/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftStatisticsPublisher.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftStatisticsPublisher.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftStatisticsPublisher.java
index c26c6d3..bf0db61 100644
--- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftStatisticsPublisher.java
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftStatisticsPublisher.java
@@ -43,6 +43,8 @@ public class ThriftStatisticsPublisher implements StatisticsPublisher {
private LoadBalancingDataPublisher loadBalancingDataPublisher;
private List<ThriftClientInfo> thriftClientInfoList;
private boolean enabled = false;
+ private ArrayList<ReceiverGroup> receiverGroups;
+ private ArrayList<DataPublisherHolder> dataPublisherHolders;
/**
* Credential information stored inside thrift-client-config.xml file
@@ -58,6 +60,8 @@ public class ThriftStatisticsPublisher implements StatisticsPublisher {
if (isPublisherEnabled()) {
this.enabled = true;
+ receiverGroups = new ArrayList<ReceiverGroup>();
+ dataPublisherHolders = new ArrayList<DataPublisherHolder>();
init();
}
}
@@ -82,23 +86,17 @@ public class ThriftStatisticsPublisher implements StatisticsPublisher {
private ArrayList<ReceiverGroup> getReceiverGroups() {
- ArrayList<ReceiverGroup> receiverGroups = new ArrayList<ReceiverGroup>();
- ArrayList<DataPublisherHolder> dataPublisherHolders = new ArrayList<DataPublisherHolder>();
- DataPublisherHolder aNode;
-
for (ThriftClientInfo thriftClientInfo : thriftClientInfoList) {
if (thriftClientInfo.isStatsPublisherEnabled()) {
- aNode = new DataPublisherHolder(null, buildUrl(thriftClientInfo), thriftClientInfo.getUsername(),
- thriftClientInfo.getPassword());
- dataPublisherHolders.add(aNode);
+ dataPublisherHolders.add(new DataPublisherHolder(null, buildUrl(thriftClientInfo), thriftClientInfo.getUsername(),
+ thriftClientInfo.getPassword()));
if (log.isDebugEnabled()) {
log.debug(String.format("Thrift client [id] %s [ip] %s [port] %s is added to data publisher holder",
thriftClientInfo.getId(), thriftClientInfo.getIp(), thriftClientInfo.getPort()));
}
}
}
- ReceiverGroup group = new ReceiverGroup(dataPublisherHolders);
- receiverGroups.add(group);
+ receiverGroups.add(new ReceiverGroup(dataPublisherHolders));
return receiverGroups;
}
@@ -107,6 +105,10 @@ public class ThriftStatisticsPublisher implements StatisticsPublisher {
return String.format("tcp://%s:%s", thriftClientInfo.getIp(), thriftClientInfo.getPort());
}
+ public ArrayList<DataPublisherHolder> getDataPublisherHolders() {
+ return dataPublisherHolders;
+ }
+
@Override
public void setEnabled(boolean enabled) {
this.enabled = enabled;
http://git-wip-us.apache.org/repos/asf/stratos/blob/5435bffd/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/ThriftClientConfigParserTest.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/ThriftClientConfigParserTest.java b/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/ThriftClientConfigParserTest.java
index ae7e059..26cba9f 100644
--- a/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/ThriftClientConfigParserTest.java
+++ b/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/ThriftClientConfigParserTest.java
@@ -20,7 +20,6 @@
package org.apache.stratos.common.test;
import junit.framework.TestCase;
-
import org.apache.stratos.common.statistics.publisher.ThriftClientConfig;
import org.apache.stratos.common.statistics.publisher.ThriftClientInfo;
import org.junit.Test;
@@ -44,48 +43,58 @@ public class ThriftClientConfigParserTest extends TestCase {
URL configFileUrl = ThriftClientConfigParserTest.class.getResource("/thrift-client-config.xml");
System.setProperty(ThriftClientConfig.THRIFT_CLIENT_CONFIG_FILE_PATH, configFileUrl.getPath());
ThriftClientConfig thriftClientConfig = ThriftClientConfig.getInstance();
- List <ThriftClientInfo> cepList = thriftClientConfig.getThriftClientInfo(
+ List<ThriftClientInfo> cepList = thriftClientConfig.getThriftClientInfo(
ThriftClientConfig.CEP_THRIFT_CLIENT_NAME);
- List <ThriftClientInfo> dasList = thriftClientConfig.getThriftClientInfo(
+ List<ThriftClientInfo> dasList = thriftClientConfig.getThriftClientInfo(
ThriftClientConfig.DAS_THRIFT_CLIENT_NAME);
ThriftClientInfo cepNode1 = null;
ThriftClientInfo cepNode2 = null;
ThriftClientInfo dasNode1 = null;
-
+ ThriftClientInfo dasNode2 = null;
+
for (ThriftClientInfo cepNodeInfo : cepList) {
- if(cepNodeInfo.getId().equals("node-01")) {
- cepNode1 = cepNodeInfo;
- }else if(cepNodeInfo.getId().equals("node-02")) {
- cepNode2 = cepNodeInfo;
- }
- }
-
+ if (cepNodeInfo.getId().equals("node-01")) {
+ cepNode1 = cepNodeInfo;
+ } else if (cepNodeInfo.getId().equals("node-02")) {
+ cepNode2 = cepNodeInfo;
+ }
+ }
+
for (ThriftClientInfo dasNodeInfo : dasList) {
- if(dasNodeInfo.getId().equals("node-01")) {
- dasNode1 = dasNodeInfo;
- }
- }
+ if (dasNodeInfo.getId().equals("node-01")) {
+ dasNode1 = dasNodeInfo;
+ } else if (dasNodeInfo.getId().equals("node-02")) {
+ dasNode2 = dasNodeInfo;
+ }
+ }
// CEP-node1
- assertEquals("CEP Stats Publisher not enabled",true,cepNode1.isStatsPublisherEnabled());
- assertEquals("Incorrect Username", "admincep1", cepNode1.getUsername());
- assertEquals("Incorrect Password", "1234cep1", cepNode1.getPassword());
- assertEquals("Incorrect IP", "192.168.10.10", cepNode1.getIp());
- assertEquals("Incorrect Port", "9300", cepNode1.getPort());
-
+ assertEquals("CEP stats publisher is not enabled", true, cepNode1.isStatsPublisherEnabled());
+ assertEquals("Incorrect username", "admincep1", cepNode1.getUsername());
+ assertEquals("Incorrect password", "1234cep1", cepNode1.getPassword());
+ assertEquals("Incorrect ip", "192.168.10.10", cepNode1.getIp());
+ assertEquals("Incorrect port", "9300", cepNode1.getPort());
+
// CEP-node2
- assertEquals("CEP Stats Publisher not enabled",true,cepNode2.isStatsPublisherEnabled());
- assertEquals("Incorrect Username", "admincep2", cepNode2.getUsername());
- assertEquals("Incorrect Password", "1234cep2", cepNode2.getPassword());
- assertEquals("Incorrect IP", "192.168.10.20", cepNode2.getIp());
- assertEquals("Incorrect Port", "9300", cepNode2.getPort());
+ assertEquals("CEP stats publisher is not enabled", true, cepNode2.isStatsPublisherEnabled());
+ assertEquals("Incorrect username", "admincep2", cepNode2.getUsername());
+ assertEquals("Incorrect password", "1234cep2", cepNode2.getPassword());
+ assertEquals("Incorrect ip", "192.168.10.20", cepNode2.getIp());
+ assertEquals("Incorrect port", "9300", cepNode2.getPort());
// DAS node 1
- assertEquals("DAS Stats Publisher not enabled",true, dasNode1.isStatsPublisherEnabled());
- assertEquals("Incorrect Username", "admindas1", dasNode1.getUsername());
- assertEquals("Incorrect Password", "1234das1", dasNode1.getPassword());
- assertEquals("Incorrect IP", "192.168.10.11", dasNode1.getIp());
- assertEquals("Incorrect Port", "9301", dasNode1.getPort());
-
+ assertEquals("DAS stats publisher is not enabled", true, dasNode1.isStatsPublisherEnabled());
+ assertEquals("Incorrect username", "admindas1", dasNode1.getUsername());
+ assertEquals("Incorrect password", "1234das1", dasNode1.getPassword());
+ assertEquals("Incorrect ip", "192.168.10.11", dasNode1.getIp());
+ assertEquals("Incorrect port", "9301", dasNode1.getPort());
+
+ // DAS node 2
+ assertEquals("DAS stats publisher is enabled", false, dasNode2.isStatsPublisherEnabled());
+ assertEquals("Incorrect username", "admindas2", dasNode2.getUsername());
+ assertEquals("Incorrect password", "1234das2", dasNode2.getPassword());
+ assertEquals("Incorrect ip", "192.168.10.21", dasNode2.getIp());
+ assertEquals("Incorrect port", "9301", dasNode2.getPort());
+
}
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/5435bffd/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/ThriftStatisticsPublisherTest.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/ThriftStatisticsPublisherTest.java b/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/ThriftStatisticsPublisherTest.java
new file mode 100644
index 0000000..43cd4c1
--- /dev/null
+++ b/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/ThriftStatisticsPublisherTest.java
@@ -0,0 +1,60 @@
+/*
+* 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 org.apache.stratos.common.test;
+
+import org.apache.stratos.common.statistics.publisher.ThriftClientConfig;
+import org.apache.stratos.common.statistics.publisher.ThriftStatisticsPublisher;
+import org.junit.Test;
+import org.wso2.carbon.databridge.commons.StreamDefinition;
+
+import java.net.URL;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * ThriftStatisticsPublisherTest
+ */
+public class ThriftStatisticsPublisherTest {
+ /**
+ * Checking whether LoadBalancingDataPublisher is created for cep and das according to thrift-client-config.xml
+ *
+ * @throws Exception
+ */
+ @Test
+ public void createLoadBalancingDataPublisher() throws Exception {
+ URL configFileUrl = ThriftClientConfigParserTest.class.getResource("/thrift-client-config.xml");
+ System.setProperty(ThriftClientConfig.THRIFT_CLIENT_CONFIG_FILE_PATH, configFileUrl.getPath());
+
+ StreamDefinition streamDefinition = new StreamDefinition("Test", "1.0.0");
+
+ ThriftStatisticsPublisher thriftStatisticsPublisher = new ThriftStatisticsPublisher(streamDefinition,
+ ThriftClientConfig.CEP_THRIFT_CLIENT_NAME);
+ assertEquals("CEP stats publisher is not enabled", true, thriftStatisticsPublisher.isEnabled());
+ assertEquals("No of CEP nodes enabled for stats publishing is not equal to two", 2,
+ thriftStatisticsPublisher.getDataPublisherHolders().size());
+
+ thriftStatisticsPublisher = new ThriftStatisticsPublisher(streamDefinition,
+ ThriftClientConfig.DAS_THRIFT_CLIENT_NAME);
+ assertEquals("DAS stats publisher is not enabled", true, thriftStatisticsPublisher.isEnabled());
+ assertEquals("More than one DAS node is enabled for stats publishing", 1,
+ thriftStatisticsPublisher.getDataPublisherHolders().size());
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/5435bffd/components/org.apache.stratos.common/src/test/resources/thrift-client-config.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/test/resources/thrift-client-config.xml b/components/org.apache.stratos.common/src/test/resources/thrift-client-config.xml
index f828e0d..0d46ae6 100644
--- a/components/org.apache.stratos.common/src/test/resources/thrift-client-config.xml
+++ b/components/org.apache.stratos.common/src/test/resources/thrift-client-config.xml
@@ -20,31 +20,38 @@
<!-- Apache thrift client configuration for publishing statistics to WSO2 CEP and WSO2 DAS -->
<thriftClientConfiguration>
- <config>
+ <config>
<cep>
- <node id="node-01">
- <statsPublisherEnabled>true</statsPublisherEnabled>
- <username>admincep1</username>
- <password>1234cep1</password>
- <ip>192.168.10.10</ip>
- <port>9300</port>
- </node>
- <node id="node-02">
- <statsPublisherEnabled>true</statsPublisherEnabled>
- <username>admincep2</username>
- <password>1234cep2</password>
- <ip>192.168.10.20</ip>
- <port>9300</port>
- </node>
+ <node id="node-01">
+ <statsPublisherEnabled>true</statsPublisherEnabled>
+ <username>admincep1</username>
+ <password>1234cep1</password>
+ <ip>192.168.10.10</ip>
+ <port>9300</port>
+ </node>
+ <node id="node-02">
+ <statsPublisherEnabled>true</statsPublisherEnabled>
+ <username>admincep2</username>
+ <password>1234cep2</password>
+ <ip>192.168.10.20</ip>
+ <port>9300</port>
+ </node>
</cep>
<das>
- <node id="node-01">
- <statsPublisherEnabled>true</statsPublisherEnabled>
- <username>admindas1</username>
- <password>1234das1</password>
- <ip>192.168.10.11</ip>
- <port>9301</port>
- </node>
+ <node id="node-01">
+ <statsPublisherEnabled>true</statsPublisherEnabled>
+ <username>admindas1</username>
+ <password>1234das1</password>
+ <ip>192.168.10.11</ip>
+ <port>9301</port>
+ </node>
+ <node id="node-02">
+ <statsPublisherEnabled>false</statsPublisherEnabled>
+ <username>admindas2</username>
+ <password>1234das2</password>
+ <ip>192.168.10.21</ip>
+ <port>9301</port>
+ </node>
</das>
- </config>
+ </config>
</thriftClientConfiguration>
\ No newline at end of file