mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
adding more testcases for the analytics.publisher component.
This commit is contained in:
parent
5b9bddd667
commit
ef6e7df656
@ -18,13 +18,6 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.analytics.data.publisher;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.wso2.carbon.base.MultitenantConstants;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.databridge.agent.DataPublisher;
|
||||
import org.wso2.carbon.databridge.agent.exception.DataEndpointAgentConfigurationException;
|
||||
import org.wso2.carbon.databridge.agent.exception.DataEndpointAuthenticationException;
|
||||
@ -32,38 +25,16 @@ import org.wso2.carbon.databridge.agent.exception.DataEndpointConfigurationExcep
|
||||
import org.wso2.carbon.databridge.agent.exception.DataEndpointException;
|
||||
import org.wso2.carbon.databridge.commons.exception.TransportException;
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.config.AnalyticsConfiguration;
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherAlreadyExistsException;
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.internal.DataPublisherDataHolder;
|
||||
import org.wso2.carbon.registry.core.Registry;
|
||||
import org.wso2.carbon.registry.core.Resource;
|
||||
import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||
import org.wso2.carbon.registry.core.service.TenantRegistryLoader;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* This is used to manage data publisher per tenant.
|
||||
*/
|
||||
public class DeviceDataPublisher {
|
||||
|
||||
private static final Log log = LogFactory.getLog(DeviceDataPublisher.class);
|
||||
private static final String TENANT_DAS_CONFIG_LOCATION = "/das/config.json";
|
||||
private static final String USERNAME_CONFIG_TAG = "username";
|
||||
private static final String PASSWORD_CONFIG_TAG = "password";
|
||||
/**
|
||||
* map to store data publishers for each tenant.
|
||||
*/
|
||||
private static Map<String, DataPublisher> dataPublisherMap;
|
||||
private DataPublisher dataPublisher;
|
||||
private static DeviceDataPublisher deviceDataPublisher;
|
||||
|
||||
public DeviceDataPublisher() {
|
||||
dataPublisherMap = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public static DeviceDataPublisher getInstance() {
|
||||
if (deviceDataPublisher == null) {
|
||||
synchronized (DeviceDataPublisher.class) {
|
||||
@ -78,144 +49,43 @@ public class DeviceDataPublisher {
|
||||
/**
|
||||
* this return the data publisher for the tenant.
|
||||
*
|
||||
* @return
|
||||
* @return instance of data publisher
|
||||
* @throws DataPublisherConfigurationException
|
||||
*
|
||||
*/
|
||||
public DataPublisher getDataPublisher() throws DataPublisherConfigurationException {
|
||||
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
|
||||
//Get LoadBalancingDataPublisher which has been registered for the tenant.
|
||||
DataPublisher dataPublisher = getDataPublisher(tenantDomain);
|
||||
//If a LoadBalancingDataPublisher had not been registered for the tenant.
|
||||
if (dataPublisher == null) {
|
||||
AnalyticsConfiguration analyticsConfig = AnalyticsConfiguration.getInstance();
|
||||
if (!analyticsConfig.isEnable()) {
|
||||
return null;
|
||||
}
|
||||
String analyticsServerUrlGroups = analyticsConfig.getReceiverServerUrl();
|
||||
String analyticsServerUsername = analyticsConfig.getAdminUsername();
|
||||
String analyticsServerPassword = analyticsConfig.getAdminPassword();
|
||||
if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain)) {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
String userInfo[] = getAnalyticsServerUserInfo(tenantId);
|
||||
if (userInfo != null) {
|
||||
analyticsServerUsername = userInfo[0];
|
||||
analyticsServerPassword = userInfo[1];
|
||||
if (this.dataPublisher == null) {
|
||||
synchronized (this) {
|
||||
if (this.dataPublisher == null) {
|
||||
AnalyticsConfiguration analyticsConfig = AnalyticsConfiguration.getInstance();
|
||||
if (!analyticsConfig.isEnable()) {
|
||||
return null;
|
||||
}
|
||||
String analyticsServerUrlGroups = analyticsConfig.getReceiverServerUrl();
|
||||
String analyticsServerUsername = analyticsConfig.getAdminUsername();
|
||||
String analyticsServerPassword = analyticsConfig.getAdminPassword();
|
||||
try {
|
||||
this.dataPublisher = new DataPublisher(analyticsServerUrlGroups, analyticsServerUsername,
|
||||
analyticsServerPassword);
|
||||
} catch (DataEndpointAgentConfigurationException e) {
|
||||
throw new DataPublisherConfigurationException("Configuration Exception on data publisher for " +
|
||||
"ReceiverGroup = " + analyticsServerUrlGroups + " for username " + analyticsServerUsername, e);
|
||||
} catch (DataEndpointException e) {
|
||||
throw new DataPublisherConfigurationException("Invalid ReceiverGroup = " + analyticsServerUrlGroups, e);
|
||||
} catch (DataEndpointConfigurationException e) {
|
||||
throw new DataPublisherConfigurationException("Invalid Data endpoint configuration.", e);
|
||||
} catch (DataEndpointAuthenticationException e) {
|
||||
throw new DataPublisherConfigurationException("Authentication Failed for user " +
|
||||
analyticsServerUsername, e);
|
||||
} catch (TransportException e) {
|
||||
throw new DataPublisherConfigurationException("Error occurred while retrieving data publisher", e);
|
||||
}
|
||||
} else {
|
||||
return this.dataPublisher;
|
||||
}
|
||||
}
|
||||
//Create new DataPublisher for the tenant.
|
||||
try {
|
||||
dataPublisher = new DataPublisher(analyticsServerUrlGroups, analyticsServerUsername,
|
||||
analyticsServerPassword);
|
||||
//Add created DataPublisher.
|
||||
addDataPublisher(tenantDomain, dataPublisher);
|
||||
} catch (DataEndpointAgentConfigurationException e) {
|
||||
throw new DataPublisherConfigurationException("Configuration Exception on data publisher for " +
|
||||
"ReceiverGroup = " + analyticsServerUrlGroups + " for username " + analyticsServerUsername, e);
|
||||
} catch (DataEndpointException e) {
|
||||
throw new DataPublisherConfigurationException("Invalid ReceiverGroup = " + analyticsServerUrlGroups, e);
|
||||
} catch (DataEndpointConfigurationException e) {
|
||||
throw new DataPublisherConfigurationException("Invalid Data endpoint configuration.", e);
|
||||
} catch (DataEndpointAuthenticationException e) {
|
||||
throw new DataPublisherConfigurationException("Authentication Failed for user " +
|
||||
analyticsServerUsername, e);
|
||||
} catch (TransportException e) {
|
||||
throw new DataPublisherConfigurationException("Error occurred while retrieving data publisher", e);
|
||||
} catch (DataPublisherAlreadyExistsException e) {
|
||||
log.warn("Attempting to register a data publisher for the tenant " + tenantDomain +
|
||||
" when one already exists. Returning existing data publisher");
|
||||
return getDataPublisher(tenantDomain);
|
||||
}
|
||||
}
|
||||
return dataPublisher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the data publisher which has been registered under the tenant domain.
|
||||
*
|
||||
* @param tenantDomain - The tenant domain under which the data publisher is registered
|
||||
* @return - Instance of the DataPublisher which was registered. Null if not registered.
|
||||
*/
|
||||
private DataPublisher getDataPublisher(String tenantDomain) {
|
||||
if (dataPublisherMap.containsKey(tenantDomain)) {
|
||||
return dataPublisherMap.get(tenantDomain);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a LoadBalancingDataPublisher to the data publisher map.
|
||||
*
|
||||
* @param tenantDomain - The tenant domain under which the data publisher will be registered.
|
||||
* @param dataPublisher - Instance of the LoadBalancingDataPublisher
|
||||
* @throws DataPublisherAlreadyExistsException
|
||||
* -
|
||||
* If a data publisher has already been registered under the tenant
|
||||
* domain
|
||||
*/
|
||||
private void addDataPublisher(String tenantDomain, DataPublisher dataPublisher)
|
||||
throws DataPublisherAlreadyExistsException {
|
||||
if (dataPublisherMap.containsKey(tenantDomain)) {
|
||||
throw new DataPublisherAlreadyExistsException(
|
||||
"A DataPublisher has already been created for the tenant " + tenantDomain);
|
||||
}
|
||||
|
||||
dataPublisherMap.put(tenantDomain, dataPublisher);
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve the credential from registry
|
||||
*/
|
||||
private String[] getAnalyticsServerUserInfo(int tenantId) throws DataPublisherConfigurationException {
|
||||
try {
|
||||
String config = getConfigRegistryResourceContent(tenantId, TENANT_DAS_CONFIG_LOCATION);
|
||||
JSONObject jsonConfigforDas = new JSONObject(config);
|
||||
String credential[] = new String[2];
|
||||
credential[0] = jsonConfigforDas.getString(USERNAME_CONFIG_TAG);
|
||||
credential[1] = jsonConfigforDas.getString(PASSWORD_CONFIG_TAG);
|
||||
return credential;
|
||||
} catch (RegistryException e) {
|
||||
throw new DataPublisherConfigurationException("Failed to load the registry for tenant " + tenantId, e);
|
||||
} catch (JSONException e) {
|
||||
throw new DataPublisherConfigurationException(
|
||||
"Failed to parse the credential from the registry for tenant " + tenantId, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the credential detail from the registry for tenants.
|
||||
*
|
||||
* @param tenantId for identify tenant space.
|
||||
* @param registryLocation retrieve the config file from tenant space.
|
||||
* @return the config for tenant
|
||||
* @throws RegistryException
|
||||
*/
|
||||
private String getConfigRegistryResourceContent(int tenantId, final String registryLocation)
|
||||
throws RegistryException {
|
||||
String content = null;
|
||||
try {
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true);
|
||||
RegistryService registryService = DataPublisherDataHolder.getInstance().getRegistryService();
|
||||
if (registryService != null) {
|
||||
Registry registry = registryService.getConfigSystemRegistry(tenantId);
|
||||
this.loadTenantRegistry(tenantId);
|
||||
if (registry.resourceExists(registryLocation)) {
|
||||
Resource resource = registry.get(registryLocation);
|
||||
content = new String((byte[]) resource.getContent(), Charset.defaultCharset());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
private void loadTenantRegistry(int tenantId) throws RegistryException {
|
||||
TenantRegistryLoader tenantRegistryLoader = DataPublisherDataHolder.getInstance().getTenantRegistryLoader();
|
||||
DataPublisherDataHolder.getInstance().getIndexLoaderService().loadTenantIndex(tenantId);
|
||||
tenantRegistryLoader.loadTenantRegistry(tenantId);
|
||||
return this.dataPublisher;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -26,20 +26,4 @@ public class InvalidConfigurationStateException extends RuntimeException {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(String msg, Exception nestedEx) {
|
||||
super(msg, nestedEx);
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public InvalidConfigurationStateException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. 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.wso2.carbon.device.mgt.analytics.data.publisher.exception;
|
||||
|
||||
public class DataPublisherAlreadyExistsException extends Exception {
|
||||
public DataPublisherAlreadyExistsException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DataPublisherAlreadyExistsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public DataPublisherAlreadyExistsException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public DataPublisherAlreadyExistsException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
protected DataPublisherAlreadyExistsException(String message, Throwable cause,
|
||||
boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
||||
@ -19,9 +19,6 @@
|
||||
package org.wso2.carbon.device.mgt.analytics.data.publisher.exception;
|
||||
|
||||
public class DataPublisherConfigurationException extends Exception {
|
||||
public DataPublisherConfigurationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DataPublisherConfigurationException(String message) {
|
||||
super(message);
|
||||
@ -31,14 +28,4 @@ public class DataPublisherConfigurationException extends Exception {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public DataPublisherConfigurationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
protected DataPublisherConfigurationException(String message, Throwable cause,
|
||||
boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -23,20 +23,48 @@ import org.wso2.carbon.device.mgt.analytics.data.publisher.config.AnalyticsConfi
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.config.InvalidConfigurationStateException;
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* This test class will validate the Data publisher configuration creation.
|
||||
*/
|
||||
public class DataPublisherConfigTest extends BaseAnalyticsDataPublisherTest {
|
||||
|
||||
@Test(description = "Validating the behaviour od getInstance of the config before calling the init",
|
||||
expectedExceptions = InvalidConfigurationStateException.class)
|
||||
public void testGetInstanceWithoutInit(){
|
||||
public void testGetInstanceWithoutInit() {
|
||||
AnalyticsConfiguration.getInstance();
|
||||
}
|
||||
|
||||
@Test(description = "Validating the behaviour od getInstance of the config before calling the init",
|
||||
expectedExceptions = DataPublisherConfigurationException.class)
|
||||
public void testInitWithInvalidConfig() throws DataPublisherConfigurationException {
|
||||
AnalyticsConfiguration.init();
|
||||
ClassLoader classLoader = this.getClass().getClassLoader();
|
||||
URL invalidConfig = classLoader.getResource("carbon-home/repository/conf/etc/" +
|
||||
"device-analytics-config-invalid.xml");
|
||||
Assert.assertTrue("No configuration - device-analytics-config-invalid.xml found in resource dir",
|
||||
invalidConfig != null);
|
||||
File file = new File(invalidConfig.getFile());
|
||||
AnalyticsConfiguration.init(file.getAbsolutePath());
|
||||
}
|
||||
|
||||
@Test (description = "Validating the init method with all required params", dependsOnMethods = "testGetInstanceWithoutInit")
|
||||
public void testInit() throws DataPublisherConfigurationException {
|
||||
|
||||
@Test(description = "Validating the behaviour od getInstance of the config before calling the init",
|
||||
expectedExceptions = DataPublisherConfigurationException.class)
|
||||
public void testInitWithInvalidXML() throws DataPublisherConfigurationException {
|
||||
ClassLoader classLoader = this.getClass().getClassLoader();
|
||||
URL invalidConfig = classLoader.getResource("carbon-home/repository/conf/etc/" +
|
||||
"device-analytics-config-invalid-xml.xml");
|
||||
Assert.assertTrue("No configuration - device-analytics-config-invalid-xml.xml found in resource dir",
|
||||
invalidConfig != null);
|
||||
File file = new File(invalidConfig.getFile());
|
||||
AnalyticsConfiguration.init(file.getAbsolutePath());
|
||||
}
|
||||
|
||||
|
||||
@Test(description = "Validating the init method with all required params", dependsOnMethods = "testInitWithInvalidXML")
|
||||
public void testInitWithValidConfig() throws DataPublisherConfigurationException {
|
||||
AnalyticsConfiguration.init();
|
||||
AnalyticsConfiguration analyticsConfiguration = AnalyticsConfiguration.getInstance();
|
||||
Assert.assertEquals(analyticsConfiguration.getAdminPassword(), "testuserpwd");
|
||||
|
||||
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
* WSO2 Inc. 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.wso2.carbon.device.mgt.analytics.data.publisher;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.config.AnalyticsConfiguration;
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.config.InvalidConfigurationStateException;
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
|
||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherServiceImpl;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* This test class will test the methods that are exposed from {@link EventsPublisherService}
|
||||
*/
|
||||
public class EventPublisherServiceTest extends BaseAnalyticsDataPublisherTest {
|
||||
|
||||
private static final String STREAM_NAME = "org.wso2.test.stream";
|
||||
private static final String TENANT_DOMAIN = "test.com";
|
||||
|
||||
private EventsPublisherService eventsPublisherService;
|
||||
|
||||
@BeforeClass
|
||||
public void initTest() {
|
||||
this.eventsPublisherService = new EventsPublisherServiceImpl();
|
||||
}
|
||||
|
||||
@Test(description = "Publish the event before initializing",
|
||||
expectedExceptions = InvalidConfigurationStateException.class)
|
||||
public void publishBeforeInit() throws DataPublisherConfigurationException, NoSuchFieldException,
|
||||
IllegalAccessException, InstantiationException {
|
||||
Field configField = AnalyticsConfiguration.class.getDeclaredField("config");
|
||||
configField.setAccessible(true);
|
||||
configField.set(configField, null);
|
||||
this.eventsPublisherService.publishEvent(STREAM_NAME, "1.0.0", getEventProps(), getEventProps(),
|
||||
getEventProps());
|
||||
}
|
||||
|
||||
@Test(description = "Publish with analytics config disabled", dependsOnMethods = "publishBeforeInit")
|
||||
public void publishWhenAnalyticsConfigDisabled() throws DataPublisherConfigurationException {
|
||||
AnalyticsConfiguration.init();
|
||||
AnalyticsConfiguration.getInstance().setEnable(false);
|
||||
boolean published = this.eventsPublisherService.publishEvent(STREAM_NAME, "1.0.0", getEventProps(),
|
||||
getEventProps(), getEventProps());
|
||||
Assert.assertFalse(published);
|
||||
}
|
||||
|
||||
@Test(description = "Publish the event after initializing", dependsOnMethods = "publishWhenAnalyticsConfigDisabled")
|
||||
public void publishAfterInit() throws DataPublisherConfigurationException {
|
||||
AnalyticsConfiguration.getInstance().setEnable(true);
|
||||
boolean published = this.eventsPublisherService.publishEvent(STREAM_NAME, "1.0.0", getEventProps(),
|
||||
getEventProps(), getEventProps());
|
||||
Assert.assertTrue(published);
|
||||
}
|
||||
|
||||
@Test(description = "Publish as tenant", dependsOnMethods = "publishAfterInit")
|
||||
public void publishAsTenant() throws DataPublisherConfigurationException {
|
||||
publishAsTenant(getEventProps());
|
||||
}
|
||||
|
||||
@Test(description = "Publish the with no meta data as tenant", dependsOnMethods = "publishAsTenant",
|
||||
expectedExceptions = DataPublisherConfigurationException.class)
|
||||
public void publishAsTenantWithNoMetaData() throws DataPublisherConfigurationException {
|
||||
publishAsTenant(null);
|
||||
}
|
||||
|
||||
@Test(description = "Publish the with empty meta data as tenant", dependsOnMethods = "publishAsTenant",
|
||||
expectedExceptions = DataPublisherConfigurationException.class)
|
||||
public void publishAsTenantWithEmptyMetaData() throws DataPublisherConfigurationException {
|
||||
publishAsTenant(new Object[0]);
|
||||
}
|
||||
|
||||
private void publishAsTenant(Object[] metaData) throws DataPublisherConfigurationException {
|
||||
PrivilegedCarbonContext.startTenantFlow();
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(TENANT_DOMAIN, true);
|
||||
try {
|
||||
boolean published = this.eventsPublisherService.publishEvent(STREAM_NAME, "1.0.0", metaData,
|
||||
getEventProps(), getEventProps());
|
||||
Assert.assertTrue(published);
|
||||
} finally {
|
||||
PrivilegedCarbonContext.endTenantFlow();
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] getEventProps() {
|
||||
return new Object[]{"123"};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<!--
|
||||
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
|
||||
* WSO2 Inc. 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..
|
||||
-->
|
||||
|
||||
<DataAgentsConfiguration>
|
||||
<Agent>
|
||||
<Name>Thrift</Name>
|
||||
<DataEndpointClass>org.wso2.carbon.databridge.agent.endpoint.thrift.ThriftDataEndpoint</DataEndpointClass>
|
||||
<TrustSore>src/test/resources/client-truststore.jks</TrustSore>
|
||||
<TrustSorePassword>wso2carbon</TrustSorePassword>
|
||||
<QueueSize>32768</QueueSize>
|
||||
<BatchSize>200</BatchSize>
|
||||
<CorePoolSize>1</CorePoolSize>
|
||||
<SocketTimeoutMS>30000</SocketTimeoutMS>
|
||||
<MaxPoolSize>1</MaxPoolSize>
|
||||
<KeepAliveTimeInPool>20</KeepAliveTimeInPool>
|
||||
<ReconnectionInterval>30</ReconnectionInterval>
|
||||
<MaxTransportPoolSize>250</MaxTransportPoolSize>
|
||||
<MaxIdleConnections>250</MaxIdleConnections>
|
||||
<EvictionTimePeriod>5500</EvictionTimePeriod>
|
||||
<MinIdleTimeInPool>5000</MinIdleTimeInPool>
|
||||
<SecureMaxTransportPoolSize>250</SecureMaxTransportPoolSize>
|
||||
<SecureMaxIdleConnections>250</SecureMaxIdleConnections>
|
||||
<SecureEvictionTimePeriod>5500</SecureEvictionTimePeriod>
|
||||
<SecureMinIdleTimeInPool>5000</SecureMinIdleTimeInPool>
|
||||
<!--<sslEnabledProtocols>TLSv1,TLSv1.1,TLSv1.2</sslEnabledProtocols>-->
|
||||
<!--<ciphers>SSL_RSA_WITH_RC4_128_MD5,SSL_RSA_WITH_RC4_128_SHA,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA,SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA,SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA</ciphers>-->
|
||||
</Agent>
|
||||
|
||||
<Agent>
|
||||
<Name>Binary</Name>
|
||||
<DataEndpointClass>org.wso2.carbon.databridge.agent.endpoint.binary.BinaryDataEndpoint</DataEndpointClass>
|
||||
<TrustSore>src/test/resources/client-truststore.jks</TrustSore>
|
||||
<TrustSorePassword>wso2carbon</TrustSorePassword>
|
||||
<QueueSize>32768</QueueSize>
|
||||
<BatchSize>200</BatchSize>
|
||||
<CorePoolSize>1</CorePoolSize>
|
||||
<MaxPoolSize>1</MaxPoolSize>
|
||||
<SocketTimeoutMS>30000</SocketTimeoutMS>
|
||||
<KeepAliveTimeInPool>20</KeepAliveTimeInPool>
|
||||
<ReconnectionInterval>30</ReconnectionInterval>
|
||||
<MaxTransportPoolSize>250</MaxTransportPoolSize>
|
||||
<MaxIdleConnections>250</MaxIdleConnections>
|
||||
<EvictionTimePeriod>5500</EvictionTimePeriod>
|
||||
<MinIdleTimeInPool>5000</MinIdleTimeInPool>
|
||||
<SecureMaxTransportPoolSize>250</SecureMaxTransportPoolSize>
|
||||
<SecureMaxIdleConnections>250</SecureMaxIdleConnections>
|
||||
<SecureEvictionTimePeriod>5500</SecureEvictionTimePeriod>
|
||||
<SecureMinIdleTimeInPool>5000</SecureMinIdleTimeInPool>
|
||||
<!--<sslEnabledProtocols>TLSv1,TLSv1.1,TLSv1.2</sslEnabledProtocols>-->
|
||||
<!--<ciphers>SSL_RSA_WITH_RC4_128_MD5,SSL_RSA_WITH_RC4_128_SHA,TLS_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_RSA_WITH_AES_128_CBC_SHA,TLS_DHE_DSS_WITH_AES_128_CBC_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA,SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA,SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA</ciphers>-->
|
||||
</Agent>
|
||||
</DataAgentsConfiguration>
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<!--
|
||||
~ Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
~
|
||||
~ WSO2 Inc. 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.
|
||||
-->
|
||||
|
||||
<AnalyticsConfig>
|
||||
<!--
|
||||
Server URL of the remote DAS/BAM/CEP server used to collect statistics. Must
|
||||
be specified in protocol://hostname:port/ format.
|
||||
|
||||
An event can also be published to multiple Receiver Groups each having 1 or more receivers. Receiver
|
||||
Groups are delimited by curly braces whereas receivers are delimited by commas.
|
||||
Ex - Multiple Receivers within a single group
|
||||
tcp://localhost:7612/,tcp://localhost:7613/,tcp://localhost:7614/
|
||||
Ex - Multiple Receiver Groups with two receivers each
|
||||
{tcp://localhost:7612/,tcp://localhost:7613},{tcp://localhost:7712/,tcp://localhost:7713/}
|
||||
-->
|
||||
<ReceiverServerUrl>tcp://localhost:7615</ReceiverServerUrl>
|
||||
<AdminUsername>testuser</AdminUsername>
|
||||
<AdminPassword>testuserpwd</AdminPassword
|
||||
</AnalyticsConfig>
|
||||
@ -17,7 +17,7 @@
|
||||
~ under the License.
|
||||
-->
|
||||
|
||||
<AnalyticsConfiguration>
|
||||
<AnalyticsConfig>
|
||||
<!--
|
||||
Server URL of the remote DAS/BAM/CEP server used to collect statistics. Must
|
||||
be specified in protocol://hostname:port/ format.
|
||||
@ -32,4 +32,4 @@
|
||||
<ReceiverServerUrl>tcp://localhost:7615</ReceiverServerUrl>
|
||||
<AdminUsername>testuser</AdminUsername>
|
||||
<AdminPassword>testuserpwd</AdminPassword>
|
||||
</AnalyticsConfiguration>
|
||||
</AnalyticsConfig>
|
||||
|
||||
Binary file not shown.
@ -24,6 +24,7 @@
|
||||
<test name="Device Mgmt Analytics Data Publisher" preserve-order="true">
|
||||
<classes>
|
||||
<class name="org.wso2.carbon.device.mgt.analytics.data.publisher.DataPublisherConfigTest"/>
|
||||
<class name="org.wso2.carbon.device.mgt.analytics.data.publisher.EventPublisherServiceTest"/>
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user