X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=apiroute%2Fapiroute-service%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fmsb%2Fapiroute%2Fwrapper%2Fqueue%2FQueueManagerTest.java;h=aedda1ea24e1cb7cc780a0966bf4b27fe1645c28;hb=68cc488d5e90fedbe0286806d1490e1677ff8395;hp=1260c5f85e8854b99f06b82809b6c3da8e9efba8;hpb=e5fe5a022f4cc5164c1f4516c024617c49f12978;p=msb%2Fapigateway.git diff --git a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/queue/QueueManagerTest.java b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/queue/QueueManagerTest.java index 1260c5f..aedda1e 100644 --- a/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/queue/QueueManagerTest.java +++ b/apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/queue/QueueManagerTest.java @@ -1,17 +1,15 @@ /******************************************************************************* * Copyright 2016-2017 ZTE, Inc. and others. * - * Licensed 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 + * Licensed 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 + * 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. + * 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.onap.msb.apiroute.wrapper.queue; @@ -55,139 +53,133 @@ import com.fiftyonred.mock_jedis.MockJedisPool; import com.orbitz.consul.model.health.ImmutableNode; @RunWith(PowerMockRunner.class) -@PrepareForTest({JedisUtil.class,RouteUtil.class,RedisAccessWrapper.class}) -@PowerMockIgnore( {"javax.management.*"}) +@PrepareForTest({JedisUtil.class, RouteUtil.class, RedisAccessWrapper.class}) +@PowerMockIgnore({"javax.management.*", "jdk.internal.reflect.*"}) public class QueueManagerTest { - private static QueueManager queueManager; - - - @BeforeClass - public static void setUpBeforeClass() throws Exception { - queueManager=QueueManager.getInstance(); - putInServiceListQueue(); - putInServiceQueue4Update(); - - } - - @Before - public void setUpBeforeTest() throws Exception { - final JedisPool mockJedisPool = new MockJedisPool(new JedisPoolConfig(), "localhost"); - PowerMockito.mockStatic(JedisUtil.class); - JedisUtil jedisUtil=PowerMockito.mock(JedisUtil.class); - PowerMockito.when(jedisUtil.borrowJedisInstance()).thenReturn(mockJedisPool.getResource()); - - PowerMockito.replace(PowerMockito.method(RedisAccessWrapper.class, "filterKeys")).with(new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - return mockJedisPool.getResource().keys((String) args[0]); - } - }); - } - - - - public void test_ServiceConsumer(){ - - //start ServiceListConsumer -// new Thread(new ServiceListConsumer(this),"ServiceListConsumerThread").start(); - - //start Service Consumer - int serviceQueneNum=RouteUtil.SERVICE_DATA_QUEUE_NUM; - for(int i=0;i data=new ServiceData(); - data.setDataType(ServiceData.DataType.service_list); - - BasicHttpEntity entity = new BasicHttpEntity(); - InputStream content = HttpTest.class.getResourceAsStream("serviceslist.json"); - entity.setContent(content); - data.setData(entity); - - try { - queueManager.putIn(data); - } catch (Exception e) { - Assert.assertTrue(e instanceof InterruptedException); + + + + public void test_ServiceConsumer() { + + // start ServiceListConsumer + // new Thread(new ServiceListConsumer(this),"ServiceListConsumerThread").start(); + + // start Service Consumer + int serviceQueneNum = RouteUtil.SERVICE_DATA_QUEUE_NUM; + for (int i = 0; i < serviceQueneNum; i++) { + new Thread(new ServiceConsumer(i), "ServiceConsumerThread" + i).start(); + } + } - } - - private static void putInServiceQueue4Update(){ - ServiceData> data=new ServiceData>(); - data.setDataType(ServiceData.DataType.service); - data.setOperate(ServiceData.Operate.delete); - - List tagList = new ArrayList(); - tagList.add("\"base\":{\"protocol\":\"REST\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}"); - tagList - .add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}"); - tagList.add("\"ns\":{\"namespace\":\"ns1\"}"); - - Service service = - ImmutableService.builder().id("id").port(8686).address("10.74.165.246").service("msbtest") - .addAllTags(tagList).createIndex(0).modifyIndex(0).build(); - ServiceHealth serviceHealth = - ImmutableServiceHealth.builder().service(service) - .node(ImmutableNode.builder().node("server").address("192.168.1.98").build()).build(); - List serviceHealthList = new ArrayList(); - serviceHealthList.add(serviceHealth); - - data.setData(serviceHealthList); - - try { - queueManager.putIn(data); - } catch (Exception e) { - Assert.assertTrue(e instanceof InterruptedException); + + + public void test_ServiceListConsumer() { + + // start ServiceListConsumer + new Thread(new ServiceListConsumer(), "ServiceListConsumerThread").start(); + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + putInServiceQueue4Delete(); } - } - - private static void putInServiceQueue4Delete(){ - ServiceData> data=new ServiceData>(); - data.setDataType(ServiceData.DataType.service); - data.setOperate(ServiceData.Operate.update); - - List tagList = new ArrayList(); - tagList.add("\"base\":{\"protocol\":\"REST\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}"); - tagList - .add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}"); - tagList.add("\"ns\":{\"namespace\":\"ns1\"}"); - - Service service = - ImmutableService.builder().id("id").port(8686).address("10.74.165.246").service("msbtest") - .addAllTags(tagList).createIndex(0).modifyIndex(0).build(); - ServiceHealth serviceHealth = - ImmutableServiceHealth.builder().service(service) - .node(ImmutableNode.builder().node("server").address("192.168.1.98").build()).build(); - List serviceHealthList = new ArrayList(); - serviceHealthList.add(serviceHealth); - - data.setData(serviceHealthList); - - try { - queueManager.putIn(data); - } catch (Exception e) { - Assert.assertTrue(e instanceof InterruptedException); + + + + private static void putInServiceListQueue() { + ServiceData data = new ServiceData(); + data.setDataType(ServiceData.DataType.service_list); + + BasicHttpEntity entity = new BasicHttpEntity(); + InputStream content = HttpTest.class.getResourceAsStream("serviceslist.json"); + entity.setContent(content); + data.setData(entity); + + try { + queueManager.putIn(data); + } catch (Exception e) { + Assert.assertTrue(e instanceof InterruptedException); + } + } + + private static void putInServiceQueue4Update() { + ServiceData> data = new ServiceData>(); + data.setDataType(ServiceData.DataType.service); + data.setOperate(ServiceData.Operate.delete); + + List tagList = new ArrayList(); + tagList.add("\"base\":{\"protocol\":\"REST\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}"); + tagList.add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}"); + tagList.add("\"ns\":{\"namespace\":\"ns1\"}"); + + Service service = ImmutableService.builder().id("id").port(8686).address("10.74.165.246").service("msbtest") + .addAllTags(tagList).createIndex(0).modifyIndex(0).build(); + ServiceHealth serviceHealth = ImmutableServiceHealth.builder().service(service) + .node(ImmutableNode.builder().node("server").address("192.168.1.98").build()).build(); + List serviceHealthList = new ArrayList(); + serviceHealthList.add(serviceHealth); + + data.setData(serviceHealthList); + + try { + queueManager.putIn(data); + } catch (Exception e) { + Assert.assertTrue(e instanceof InterruptedException); + } } - } - - + + private static void putInServiceQueue4Delete() { + ServiceData> data = new ServiceData>(); + data.setDataType(ServiceData.DataType.service); + data.setOperate(ServiceData.Operate.update); + + List tagList = new ArrayList(); + tagList.add("\"base\":{\"protocol\":\"REST\",\"version\":\"v1\",\"url\":\"/api/msbtest/v1\"}"); + tagList.add("\"labels\":{\"visualRange\":\"0\",\"network_plane_type\":\"net\",\"customLabel\":\"custom\"}"); + tagList.add("\"ns\":{\"namespace\":\"ns1\"}"); + + Service service = ImmutableService.builder().id("id").port(8686).address("10.74.165.246").service("msbtest") + .addAllTags(tagList).createIndex(0).modifyIndex(0).build(); + ServiceHealth serviceHealth = ImmutableServiceHealth.builder().service(service) + .node(ImmutableNode.builder().node("server").address("192.168.1.98").build()).build(); + List serviceHealthList = new ArrayList(); + serviceHealthList.add(serviceHealth); + + data.setData(serviceHealthList); + + try { + queueManager.putIn(data); + } catch (Exception e) { + Assert.assertTrue(e instanceof InterruptedException); + } + } + + }