diff options
author | HuabingZhao <zhao.huabing@zte.com.cn> | 2017-09-07 14:33:18 +0800 |
---|---|---|
committer | HuabingZhao <zhao.huabing@zte.com.cn> | 2017-09-07 14:40:59 +0800 |
commit | e75a8ef2372722c0b22669fb427d47bacc5b8d5e (patch) | |
tree | cee85cbc4fe818262fb8c4d733f2fac0c8024df8 /apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/queue | |
parent | e5fe5a022f4cc5164c1f4516c024617c49f12978 (diff) |
Fix java check style warning
Change-Id: I98a6d7237a213d007ad4d954989cb0b0fa150a10
Issue-Id: MSB-67
Signed-off-by: HuabingZhao <zhao.huabing@zte.com.cn>
Diffstat (limited to 'apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/queue')
-rw-r--r-- | apiroute/apiroute-service/src/test/java/org/onap/msb/apiroute/wrapper/queue/QueueManagerTest.java | 268 |
1 files changed, 130 insertions, 138 deletions
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..931c09d 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.*"}) 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<serviceQueneNum;i++){ - new Thread(new ServiceConsumer(i),"ServiceConsumerThread"+i).start(); + private static QueueManager queueManager; + + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + queueManager = QueueManager.getInstance(); + putInServiceListQueue(); + putInServiceQueue4Update(); + } - - } - - - 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(); + + @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]); + } + }); } - putInServiceQueue4Delete(); - } - - - - private static void putInServiceListQueue(){ - ServiceData<HttpEntity> data=new ServiceData<HttpEntity>(); - 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<List<ServiceHealth>> data=new ServiceData<List<ServiceHealth>>(); - data.setDataType(ServiceData.DataType.service); - data.setOperate(ServiceData.Operate.delete); - - List<String> tagList = new ArrayList<String>(); - 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<ServiceHealth> serviceHealthList = new ArrayList<ServiceHealth>(); - 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<List<ServiceHealth>> data=new ServiceData<List<ServiceHealth>>(); - data.setDataType(ServiceData.DataType.service); - data.setOperate(ServiceData.Operate.update); - - List<String> tagList = new ArrayList<String>(); - 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<ServiceHealth> serviceHealthList = new ArrayList<ServiceHealth>(); - serviceHealthList.add(serviceHealth); - - data.setData(serviceHealthList); - - try { - queueManager.putIn(data); - } catch (Exception e) { - Assert.assertTrue(e instanceof InterruptedException); + + + + private static void putInServiceListQueue() { + ServiceData<HttpEntity> data = new ServiceData<HttpEntity>(); + 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<List<ServiceHealth>> data = new ServiceData<List<ServiceHealth>>(); + data.setDataType(ServiceData.DataType.service); + data.setOperate(ServiceData.Operate.delete); + + List<String> tagList = new ArrayList<String>(); + 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<ServiceHealth> serviceHealthList = new ArrayList<ServiceHealth>(); + serviceHealthList.add(serviceHealth); + + data.setData(serviceHealthList); + + try { + queueManager.putIn(data); + } catch (Exception e) { + Assert.assertTrue(e instanceof InterruptedException); + } } - } - - + + private static void putInServiceQueue4Delete() { + ServiceData<List<ServiceHealth>> data = new ServiceData<List<ServiceHealth>>(); + data.setDataType(ServiceData.DataType.service); + data.setOperate(ServiceData.Operate.update); + + List<String> tagList = new ArrayList<String>(); + 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<ServiceHealth> serviceHealthList = new ArrayList<ServiceHealth>(); + serviceHealthList.add(serviceHealth); + + data.setData(serviceHealthList); + + try { + queueManager.putIn(data); + } catch (Exception e) { + Assert.assertTrue(e instanceof InterruptedException); + } + } + + } |