提交 b4ded22c 编写于 作者: L lican 提交者: 彭勇升 pengys

add some basic testcase(apm-util and partial collector-ui-jetty-provider) (#1072)

* commons testcase

* some ui module query testcase

* add testcase

* fix some checkStyle issue

* add some null testcase

* remove

* add license

* fix author error

* remove invalid tag @date

* add license which has been missed
上级 daceca28
/*
* 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.skywalking.apm.collector.ui.mutation;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
/**
* this class may not be implemented ,so just test if it's null
* if update the class ,please update the testcase
* @author lican
*/
public class ConfigMutationTest {
@Before
public void setUp() throws Exception {
}
@Test
public void setDataTTLConfigs() {
ConfigMutation configMutation = new ConfigMutation();
Boolean aBoolean = configMutation.setDataTTLConfigs(null);
Assert.assertNull(aBoolean);
}
@Test
public void setAlarmThreshold() {
ConfigMutation configMutation = new ConfigMutation();
Boolean aBoolean = configMutation.setAlarmThreshold(null);
Assert.assertNull(aBoolean);
}
}
\ No newline at end of file
/*
* 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.skywalking.apm.collector.ui.query;
import org.apache.skywalking.apm.collector.storage.ui.alarm.AlarmType;
import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
import org.apache.skywalking.apm.collector.storage.ui.common.Pagination;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.ui.service.AlarmService;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import java.text.ParseException;
/**
* @author lican
*/
public class AlarmQueryTestCase {
@Test
public void testLoadAlarmList() throws ParseException {
AlarmQuery query = new AlarmQuery(null);
AlarmService alarmService = Mockito.mock(AlarmService.class);
Whitebox.setInternalState(query, "alarmService", alarmService);
Mockito.when(alarmService.loadApplicationAlarmList(
Mockito.anyString(), Mockito.anyObject(),
Mockito.anyLong(), Mockito.anyLong(), Mockito.anyInt(), Mockito.anyInt()
)).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701000000L, arguments[2]);
Assert.assertEquals(201701999999L, arguments[3]);
return null;
});
Mockito.when(alarmService.loadInstanceAlarmList(
Mockito.anyString(), Mockito.anyObject(),
Mockito.anyLong(), Mockito.anyLong(), Mockito.anyInt(), Mockito.anyInt()
)).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701000000L, arguments[2]);
Assert.assertEquals(201701999999L, arguments[3]);
return null;
});
Mockito.when(alarmService.loadServiceAlarmList(
Mockito.anyString(), Mockito.anyObject(),
Mockito.anyLong(), Mockito.anyLong(), Mockito.anyInt(), Mockito.anyInt()
)).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701000000L, arguments[2]);
Assert.assertEquals(201701999999L, arguments[3]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-01");
duration.setStep(Step.MONTH);
Pagination pagination = new Pagination();
query.loadAlarmList("keyword", AlarmType.APPLICATION, duration, pagination);
query.loadAlarmList("keyword", AlarmType.SERVER, duration, pagination);
query.loadAlarmList("keyword", AlarmType.SERVICE, duration, pagination);
}
}
...@@ -18,15 +18,18 @@ ...@@ -18,15 +18,18 @@
package org.apache.skywalking.apm.collector.ui.query; package org.apache.skywalking.apm.collector.ui.query;
import java.text.ParseException;
import org.apache.skywalking.apm.collector.storage.ui.common.Duration; import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
import org.apache.skywalking.apm.collector.storage.ui.common.Step; import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.ui.service.ApplicationService; import org.apache.skywalking.apm.collector.ui.service.ApplicationService;
import org.apache.skywalking.apm.collector.ui.service.ApplicationTopologyService;
import org.apache.skywalking.apm.collector.ui.service.ServerService;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox; import org.mockito.internal.util.reflection.Whitebox;
import java.text.ParseException;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
...@@ -37,7 +40,6 @@ public class ApplicationQueryTestCase { ...@@ -37,7 +40,6 @@ public class ApplicationQueryTestCase {
ApplicationQuery query = new ApplicationQuery(null); ApplicationQuery query = new ApplicationQuery(null);
ApplicationService applicationService = Mockito.mock(ApplicationService.class); ApplicationService applicationService = Mockito.mock(ApplicationService.class);
Whitebox.setInternalState(query, "applicationService", applicationService); Whitebox.setInternalState(query, "applicationService", applicationService);
Mockito.when(applicationService.getApplications(Mockito.anyLong(), Mockito.anyLong())).then(invocation -> { Mockito.when(applicationService.getApplications(Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
Object[] arguments = invocation.getArguments(); Object[] arguments = invocation.getArguments();
Assert.assertEquals(20170100000000L, arguments[0]); Assert.assertEquals(20170100000000L, arguments[0]);
...@@ -136,4 +138,91 @@ public class ApplicationQueryTestCase { ...@@ -136,4 +138,91 @@ public class ApplicationQueryTestCase {
query.getAllApplication(duration); query.getAllApplication(duration);
} }
@Test
public void testGetSlowByMonthDuration() throws ParseException {
ApplicationQuery query = new ApplicationQuery(null);
ApplicationService applicationService = Mockito.mock(ApplicationService.class);
Whitebox.setInternalState(query, "applicationService", applicationService);
Mockito.when(applicationService.getSlowService(
Mockito.anyInt(), Mockito.anyObject(),
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyInt())
).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[2]);
Assert.assertEquals(201701L, arguments[3]);
Assert.assertEquals(20170100000000L, arguments[4]);
Assert.assertEquals(20170199999999L, arguments[5]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-01");
// the step in exchangeToTimeBucket and startTimeDurationToSecondTimeBucket and endTimeDurationToSecondTimeBucket has its own testcase,so here wo give
// one step is enough.
duration.setStep(Step.MONTH);
query.getSlowService(-1, duration, -1);
}
@Test
public void testGetServerThroughput() throws ParseException {
ApplicationQuery query = new ApplicationQuery(null);
ServerService serverService = Mockito.mock(ServerService.class);
Whitebox.setInternalState(query, "serverService", serverService);
Mockito.when(serverService.getServerThroughput(
Mockito.anyInt(), Mockito.anyObject(),
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyInt())
).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[2]);
Assert.assertEquals(201702L, arguments[3]);
Assert.assertEquals(20170100000000L, arguments[4]);
Assert.assertEquals(20170299999999L, arguments[5]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
query.getServerThroughput(-1, duration, -1);
}
@Test
public void testGetApplicationTopology() throws ParseException {
ApplicationQuery query = new ApplicationQuery(null);
ApplicationTopologyService applicationTopologyService = Mockito.mock(ApplicationTopologyService.class);
Whitebox.setInternalState(query, "applicationTopologyService", applicationTopologyService);
Mockito.when(
applicationTopologyService.getApplicationTopology(
Mockito.anyObject(), Mockito.anyInt(),
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyLong(), Mockito.anyLong())
).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[2]);
Assert.assertEquals(201703L, arguments[3]);
Assert.assertEquals(20170100000000L, arguments[4]);
Assert.assertEquals(20170399999999L, arguments[5]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-03");
duration.setStep(Step.MONTH);
query.getApplicationTopology(-1, duration);
}
} }
/*
* 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.skywalking.apm.collector.ui.query;
import org.apache.skywalking.apm.collector.storage.ui.config.ExistedAlarmThresholds;
import org.apache.skywalking.apm.collector.storage.ui.config.ExistedTTLConfigs;
import org.junit.Assert;
import org.junit.Test;
/**
* target code may not implement yet
*
* @author lican
*/
public class ConfigQueryTest {
@Test
public void queryAllDataTTLConfigs() {
ConfigQuery configQuery = new ConfigQuery();
ExistedTTLConfigs existedTTLConfigs = configQuery.queryAllDataTTLConfigs();
Assert.assertNull(existedTTLConfigs);
}
@Test
public void queryAlarmThresholds() {
ConfigQuery configQuery = new ConfigQuery();
ExistedAlarmThresholds existedAlarmThresholds = configQuery.queryAlarmThresholds(null);
Assert.assertNull(existedAlarmThresholds);
}
}
\ No newline at end of file
/*
* 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.skywalking.apm.collector.ui.query;
import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.overview.ClusterBrief;
import org.apache.skywalking.apm.collector.ui.service.*;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import java.text.ParseException;
import java.util.Collections;
/**
* @author lican
*/
public class OverViewLayerQueryTest {
private ClusterTopologyService clusterTopologyService;
private ApplicationService applicationService;
private NetworkAddressService networkAddressService;
private ServiceNameService serviceNameService;
private AlarmService alarmService;
private OverViewLayerQuery overViewLayerQuery;
@Before
public void setUp() throws Exception {
overViewLayerQuery = new OverViewLayerQuery(null);
alarmService = Mockito.mock(AlarmService.class);
serviceNameService = Mockito.mock(ServiceNameService.class);
networkAddressService = Mockito.mock(NetworkAddressService.class);
applicationService = Mockito.mock(ApplicationService.class);
clusterTopologyService = Mockito.mock(ClusterTopologyService.class);
Whitebox.setInternalState(overViewLayerQuery, "alarmService", alarmService);
Whitebox.setInternalState(overViewLayerQuery, "serviceNameService", serviceNameService);
Whitebox.setInternalState(overViewLayerQuery, "networkAddressService", networkAddressService);
Whitebox.setInternalState(overViewLayerQuery, "applicationService", applicationService);
Whitebox.setInternalState(overViewLayerQuery, "clusterTopologyService", clusterTopologyService);
}
@Test
public void getClusterTopology() throws ParseException {
Mockito.when(
clusterTopologyService.getClusterTopology(
Mockito.anyObject(),
Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyLong())
).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[1]);
Assert.assertEquals(201702L, arguments[2]);
Assert.assertEquals(20170100000000L, arguments[3]);
Assert.assertEquals(20170299999999L, arguments[4]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
overViewLayerQuery.getClusterTopology(duration);
}
@Test
public void getClusterBrief() throws ParseException {
Mockito.when(applicationService.getApplications(Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(20170100000000L, arguments[0]);
Assert.assertEquals(20170299999999L, arguments[1]);
return Collections.emptyList();
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
ClusterBrief clusterBrief = overViewLayerQuery.getClusterBrief(duration);
Assert.assertNotNull(clusterBrief);
}
@Test
public void getAlarmTrend() throws ParseException {
Mockito.when(
alarmService.getApplicationAlarmTrend(
Mockito.anyObject(),
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyLong(), Mockito.anyLong())
).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[1]);
Assert.assertEquals(201702L, arguments[2]);
Assert.assertEquals(20170100000000L, arguments[3]);
Assert.assertEquals(20170299999999L, arguments[4]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
overViewLayerQuery.getAlarmTrend(duration);
}
@Test
public void getConjecturalApps() throws ParseException {
Mockito.when(
applicationService.getConjecturalApps(
Mockito.anyObject(),
Mockito.anyLong(), Mockito.anyLong())
).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(20170100000000L, arguments[1]);
Assert.assertEquals(20170299999999L, arguments[2]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
overViewLayerQuery.getConjecturalApps(duration);
}
@Test
public void getTopNSlowService() throws ParseException {
Mockito.when(serviceNameService.getSlowService(
Mockito.anyObject(),
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyInt()
)).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[1]);
Assert.assertEquals(201702L, arguments[2]);
Assert.assertEquals(20170100000000L, arguments[3]);
Assert.assertEquals(20170299999999L, arguments[4]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
overViewLayerQuery.getTopNSlowService(duration, -1);
}
@Test
public void getTopNApplicationThroughput() throws ParseException {
Mockito.when(applicationService.getTopNApplicationThroughput(
Mockito.anyObject(),
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyInt()
)).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[1]);
Assert.assertEquals(201702L, arguments[2]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
overViewLayerQuery.getTopNApplicationThroughput(duration, -1);
}
}
\ No newline at end of file
/*
* 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.skywalking.apm.collector.ui.query;
import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.ui.service.ServerService;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import java.text.ParseException;
/**
* @author lican
*/
public class ServerQueryTest {
private ServerService serverService;
private ServerQuery serverQuery;
@Before
public void setUp() {
serverQuery = new ServerQuery(null);
serverService = Mockito.mock(ServerService.class);
Whitebox.setInternalState(serverQuery, "serverService", serverService);
}
@Test
public void searchServer() throws ParseException {
Mockito.when(serverService.searchServer(Mockito.anyString(), Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(20170100000000L, arguments[1]);
Assert.assertEquals(20170299999999L, arguments[2]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
serverQuery.searchServer("keyword", duration);
}
@Test
public void getAllServer() throws ParseException {
Mockito.when(serverService.getAllServer(Mockito.anyInt(), Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(20170100000000L, arguments[1]);
Assert.assertEquals(20170299999999L, arguments[2]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
serverQuery.getAllServer(-1, duration);
}
@Test
public void getServerResponseTimeTrend() throws ParseException {
Mockito.when(serverService.getServerResponseTimeTrend(Mockito.anyInt(), Mockito.anyObject(), Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[2]);
Assert.assertEquals(201702L, arguments[3]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
serverQuery.getServerResponseTimeTrend(-1, duration);
}
@Test
public void getServerTPSTrend() throws ParseException {
Mockito.when(serverService.getServerTPSTrend(Mockito.anyInt(), Mockito.anyObject(), Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[2]);
Assert.assertEquals(201702L, arguments[3]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
serverQuery.getServerTPSTrend(-1, duration);
}
@Test
public void getCPUTrend() throws ParseException {
Mockito.when(serverService.getCPUTrend(Mockito.anyInt(), Mockito.anyObject(), Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[2]);
Assert.assertEquals(201702L, arguments[3]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
serverQuery.getCPUTrend(-1, duration);
}
@Test
public void getGCTrend() throws ParseException {
Mockito.when(serverService.getGCTrend(Mockito.anyInt(), Mockito.anyObject(), Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[2]);
Assert.assertEquals(201702L, arguments[3]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
serverQuery.getGCTrend(-1, duration);
}
@Test
public void getMemoryTrend() throws ParseException {
Mockito.when(serverService.getMemoryTrend(Mockito.anyInt(), Mockito.anyObject(), Mockito.anyLong(), Mockito.anyLong())).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[2]);
Assert.assertEquals(201702L, arguments[3]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
serverQuery.getMemoryTrend(-1, duration);
}
}
\ No newline at end of file
/*
* 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.skywalking.apm.collector.ui.query;
import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.ui.service.ServiceNameService;
import org.apache.skywalking.apm.collector.ui.service.ServiceTopologyService;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import java.text.ParseException;
/**
* @author lican
*/
public class ServiceQueryTest {
private ServiceNameService serviceNameService;
private ServiceTopologyService serviceTopologyService;
private ServiceQuery serviceQuery;
@Before
public void setUp() throws Exception {
serviceQuery = new ServiceQuery(null);
serviceNameService = Mockito.mock(ServiceNameService.class);
serviceTopologyService = Mockito.mock(ServiceTopologyService.class);
Whitebox.setInternalState(serviceQuery, "serviceNameService", serviceNameService);
Whitebox.setInternalState(serviceQuery, "serviceTopologyService", serviceTopologyService);
}
@Test
public void searchService() throws ParseException {
serviceQuery.searchService("keyword", -1);
}
@Test
public void getServiceResponseTimeTrend() throws ParseException {
Mockito.when(serviceNameService.getServiceResponseTimeTrend(
Mockito.anyInt(), Mockito.anyObject(),
Mockito.anyLong(), Mockito.anyLong())
).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[2]);
Assert.assertEquals(201702L, arguments[3]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
serviceQuery.getServiceResponseTimeTrend(-1, duration);
}
@Test
public void getServiceTPSTrend() throws ParseException {
Mockito.when(serviceNameService.getServiceTPSTrend(
Mockito.anyInt(), Mockito.anyObject(),
Mockito.anyLong(), Mockito.anyLong())
).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[2]);
Assert.assertEquals(201702L, arguments[3]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
serviceQuery.getServiceTPSTrend(-1, duration);
}
@Test
public void getServiceSLATrend() throws ParseException {
Mockito.when(serviceNameService.getServiceSLATrend(
Mockito.anyInt(), Mockito.anyObject(),
Mockito.anyLong(), Mockito.anyLong())
).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[2]);
Assert.assertEquals(201702L, arguments[3]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
serviceQuery.getServiceSLATrend(-1, duration);
}
@Test
public void getServiceTopology() throws ParseException {
Mockito.when(serviceTopologyService.getServiceTopology(
Mockito.anyObject(), Mockito.anyInt(),
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyLong(), Mockito.anyLong())
).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(201701L, arguments[2]);
Assert.assertEquals(201702L, arguments[3]);
Assert.assertEquals(20170100000000L, arguments[4]);
Assert.assertEquals(20170299999999L, arguments[5]);
return null;
});
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
serviceQuery.getServiceTopology(-1, duration);
}
}
\ No newline at end of file
/*
* 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.skywalking.apm.collector.ui.query;
import org.apache.commons.lang3.StringUtils;
import org.apache.skywalking.apm.collector.storage.ui.common.Duration;
import org.apache.skywalking.apm.collector.storage.ui.common.Pagination;
import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.ui.trace.TraceQueryCondition;
import org.apache.skywalking.apm.collector.ui.service.SegmentTopService;
import org.apache.skywalking.apm.collector.ui.service.TraceStackService;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.internal.util.reflection.Whitebox;
import java.text.ParseException;
/**
* @author lican
*/
public class TraceQueryTest {
private SegmentTopService segmentTopService;
private TraceStackService traceStackService;
private TraceQuery traceQuery;
@Before
public void setUp() throws Exception {
traceQuery = new TraceQuery(null);
segmentTopService = Mockito.mock(SegmentTopService.class);
traceStackService = Mockito.mock(TraceStackService.class);
Whitebox.setInternalState(traceQuery, "segmentTopService", segmentTopService);
Whitebox.setInternalState(traceQuery, "traceStackService", traceStackService);
}
@Test
public void queryBasicTraces() throws ParseException {
TraceQueryCondition traceQueryCondition = new TraceQueryCondition();
traceQueryCondition.setApplicationId(-1);
traceQueryCondition.setOperationName("operationName");
Duration duration = new Duration();
duration.setStart("2017-01");
duration.setEnd("2017-02");
duration.setStep(Step.MONTH);
traceQueryCondition.setQueryDuration(duration);
traceQueryCondition.setPaging(new Pagination());
Mockito.when(segmentTopService.loadTop(
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyLong(), Mockito.anyLong(),
Mockito.anyString(), Mockito.anyString(),
Mockito.anyInt(), Mockito.anyInt(), Mockito.anyInt()
)
).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(arguments[5], StringUtils.trimToEmpty(traceQueryCondition.getTraceId()));
if (StringUtils.isBlank(traceQueryCondition.getTraceId())) {
Assert.assertEquals(20170100000000L, arguments[0]);
Assert.assertEquals(20170299999999L, arguments[1]);
} else {
Assert.assertEquals(0L, arguments[0]);
Assert.assertEquals(0L, arguments[1]);
}
return null;
});
traceQuery.queryBasicTraces(traceQueryCondition);
traceQueryCondition.setTraceId("12.12");
traceQuery.queryBasicTraces(traceQueryCondition);
}
@Test
public void queryTrace() {
String traceId = "12.12";
Mockito.when(traceStackService.load(Mockito.anyString())
).then(invocation -> {
Object[] arguments = invocation.getArguments();
Assert.assertEquals(arguments[0], traceId);
return null;
});
traceQuery.queryTrace(traceId);
}
}
\ No newline at end of file
/*
* 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.skywalking.apm.collector.ui.utils;
import org.junit.Assert;
import org.junit.Test;
/**
* @author lican
*/
public class ApdexCalculatorTest {
/**
* about apdex: https://en.wikipedia.org/wiki/Apdex
*/
@Test
public void testApdexCalculator() {
int apdex = ApdexCalculator.INSTANCE.calculate(80, 10, 10);
Assert.assertEquals(apdex, 85, 1);
}
}
...@@ -18,14 +18,15 @@ ...@@ -18,14 +18,15 @@
package org.apache.skywalking.apm.collector.ui.utils; package org.apache.skywalking.apm.collector.ui.utils;
import java.text.ParseException;
import java.util.List;
import org.apache.skywalking.apm.collector.core.UnexpectedException; import org.apache.skywalking.apm.collector.core.UnexpectedException;
import org.apache.skywalking.apm.collector.storage.ui.common.Step; import org.apache.skywalking.apm.collector.storage.ui.common.Step;
import org.apache.skywalking.apm.collector.storage.utils.DurationPoint; import org.apache.skywalking.apm.collector.storage.utils.DurationPoint;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import java.text.ParseException;
import java.util.List;
/** /**
* @author peng-yongsheng * @author peng-yongsheng
*/ */
...@@ -145,4 +146,23 @@ public class DurationUtilsTestCase { ...@@ -145,4 +146,23 @@ public class DurationUtilsTestCase {
secondTimeBucket = DurationUtils.INSTANCE.endTimeDurationToSecondTimeBucket(Step.SECOND, "20171001080501"); secondTimeBucket = DurationUtils.INSTANCE.endTimeDurationToSecondTimeBucket(Step.SECOND, "20171001080501");
Assert.assertEquals(20171001080501L, secondTimeBucket); Assert.assertEquals(20171001080501L, secondTimeBucket);
} }
@Test
public void testSecondsBetween() throws ParseException {
int secondsBetweenMonth = DurationUtils.INSTANCE.secondsBetween(Step.MONTH, 201804L, 201805L);
Assert.assertEquals(secondsBetweenMonth, 30 * 24 * 3600);
int secondsBetweenDay = DurationUtils.INSTANCE.secondsBetween(Step.DAY, 20180401L, 20180402L);
Assert.assertEquals(secondsBetweenDay, 24 * 3600);
int secondsBetweenHour = DurationUtils.INSTANCE.secondsBetween(Step.HOUR, 2018040101L, 2018040102L);
Assert.assertEquals(secondsBetweenHour, 3600);
int secondsBetweenMinute = DurationUtils.INSTANCE.secondsBetween(Step.MINUTE, 201804010100L, 201804010101L);
Assert.assertEquals(secondsBetweenMinute, 60);
int secondsBetweenSecond = DurationUtils.INSTANCE.secondsBetween(Step.SECOND, 20180401010000L, 20180401010001L);
Assert.assertEquals(secondsBetweenSecond, 1);
}
} }
/*
* 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.skywalking.apm.collector.ui.utils;
import org.junit.Assert;
import org.junit.Test;
/**
* @author lican
*/
public class SLACalculatorTest {
@Test
public void testCalculate() {
int calculate = SLACalculator.INSTANCE.calculate(20, 100);
Assert.assertEquals(80, calculate);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
~
-->
<Configuration status="info">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout charset="UTF-8" pattern="%d - %c -%-4r [%t] %-5p %x - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
...@@ -19,11 +19,13 @@ ...@@ -19,11 +19,13 @@
package org.apache.skywalking.apm.util; package org.apache.skywalking.apm.util;
import java.util.Properties;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.List;
import java.util.Properties;
/** /**
* Created by wusheng on 2017/2/27. * Created by wusheng on 2017/2/27.
*/ */
...@@ -35,6 +37,9 @@ public class ConfigInitializerTest { ...@@ -35,6 +37,9 @@ public class ConfigInitializerTest {
properties.put("Level1Object.Level2Object.INT_ATTR".toLowerCase(), "1000"); properties.put("Level1Object.Level2Object.INT_ATTR".toLowerCase(), "1000");
properties.put("Level1Object.Level2Object.LONG_ATTR".toLowerCase(), "1000"); properties.put("Level1Object.Level2Object.LONG_ATTR".toLowerCase(), "1000");
properties.put("Level1Object.Level2Object.BOOLEAN_ATTR".toLowerCase(), "true"); properties.put("Level1Object.Level2Object.BOOLEAN_ATTR".toLowerCase(), "true");
properties.put("Level1Object.LIST_ATTR".toLowerCase(), "1,2,3");
properties.put("Level1Object.LIST_EMPTY_ATTR".toLowerCase(), "");
properties.put("Level1Object.Level2Object.ENUM_ATTR".toLowerCase(), "RED");
ConfigInitializer.initialize(properties, TestPropertiesObject.class); ConfigInitializer.initialize(properties, TestPropertiesObject.class);
...@@ -42,6 +47,10 @@ public class ConfigInitializerTest { ...@@ -42,6 +47,10 @@ public class ConfigInitializerTest {
Assert.assertEquals(1000, TestPropertiesObject.Level1Object.Level2Object.INT_ATTR); Assert.assertEquals(1000, TestPropertiesObject.Level1Object.Level2Object.INT_ATTR);
Assert.assertEquals(1000L, TestPropertiesObject.Level1Object.Level2Object.LONG_ATTR); Assert.assertEquals(1000L, TestPropertiesObject.Level1Object.Level2Object.LONG_ATTR);
Assert.assertEquals(true, TestPropertiesObject.Level1Object.Level2Object.BOOLEAN_ATTR); Assert.assertEquals(true, TestPropertiesObject.Level1Object.Level2Object.BOOLEAN_ATTR);
Assert.assertArrayEquals(new String[]{}, TestPropertiesObject.Level1Object.LIST_EMPTY_ATTR.toArray());
Assert.assertEquals(TestColorEnum.RED, TestPropertiesObject.Level1Object.Level2Object.ENUM_ATTR);
//make sure that when descs is empty,toString() work right;
Assert.assertEquals(new ConfigDesc().toString(), "");
} }
@Test @Test
...@@ -57,14 +66,18 @@ public class ConfigInitializerTest { ...@@ -57,14 +66,18 @@ public class ConfigInitializerTest {
@Before @Before
public void clear() { public void clear() {
TestPropertiesObject.Level1Object.STR_ATTR = null; TestPropertiesObject.Level1Object.STR_ATTR = null;
TestPropertiesObject.Level1Object.LIST_ATTR = null;
TestPropertiesObject.Level1Object.Level2Object.INT_ATTR = 0; TestPropertiesObject.Level1Object.Level2Object.INT_ATTR = 0;
TestPropertiesObject.Level1Object.Level2Object.LONG_ATTR = 0; TestPropertiesObject.Level1Object.Level2Object.LONG_ATTR = 0;
TestPropertiesObject.Level1Object.Level2Object.BOOLEAN_ATTR = false; TestPropertiesObject.Level1Object.Level2Object.BOOLEAN_ATTR = false;
TestPropertiesObject.Level1Object.Level2Object.ENUM_ATTR = null;
} }
public static class TestPropertiesObject { public static class TestPropertiesObject {
public static class Level1Object { public static class Level1Object {
public static String STR_ATTR = null; public static String STR_ATTR = null;
public static List LIST_ATTR = null;
public static List LIST_EMPTY_ATTR = null;
public static class Level2Object { public static class Level2Object {
public static int INT_ATTR = 0; public static int INT_ATTR = 0;
...@@ -72,7 +85,13 @@ public class ConfigInitializerTest { ...@@ -72,7 +85,13 @@ public class ConfigInitializerTest {
public static long LONG_ATTR; public static long LONG_ATTR;
public static boolean BOOLEAN_ATTR; public static boolean BOOLEAN_ATTR;
public static TestColorEnum ENUM_ATTR;
}
} }
} }
private enum TestColorEnum {
RED, BLACK;
} }
} }
/*
* 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.skywalking.apm.util;
import org.junit.Assert;
import org.junit.Test;
/**
* @author lican
*/
public class MachineInfoTest {
@Test
public void testMachine() {
int processNo = MachineInfo.getProcessNo();
Assert.assertTrue(processNo >= 0);
String hostIp = MachineInfo.getHostIp();
Assert.assertTrue(!StringUtil.isEmpty(hostIp));
String hostName = MachineInfo.getHostName();
Assert.assertTrue(!StringUtil.isEmpty(hostName));
String hostDesc = MachineInfo.getHostDesc();
Assert.assertTrue(!StringUtil.isEmpty(hostDesc) && hostDesc.contains("/"));
}
}
/*
* 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.skywalking.apm.util;
import org.junit.Assert;
import org.junit.Test;
/**
* @author lican
*/
public class RunnableWithExceptionProtectionTest {
@Test
public void testProtection() {
Runnable worker = new Runnable() {
@Override
public void run() {
throw new IllegalArgumentException(" unit test exception");
}
};
RunnableWithExceptionProtection runnableWithExceptionProtection = new RunnableWithExceptionProtection(worker, new RunnableWithExceptionProtection.CallbackWhenException() {
@Override
public void handle(Throwable t) {
Assert.assertNotNull(t.getMessage());
}
});
new Thread(runnableWithExceptionProtection).start();
}
}
...@@ -19,10 +19,10 @@ ...@@ -19,10 +19,10 @@
package org.apache.skywalking.apm.agent.core.conf; package org.apache.skywalking.apm.agent.core.conf;
import org.junit.AfterClass;
import org.junit.Test;
import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException; import org.apache.skywalking.apm.agent.core.boot.AgentPackageNotFoundException;
import org.apache.skywalking.apm.agent.core.logging.core.LogLevel; import org.apache.skywalking.apm.agent.core.logging.core.LogLevel;
import org.junit.AfterClass;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册