forked from apache/dubbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for monitor module (apache#1741)
- Loading branch information
Showing
5 changed files
with
277 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...onitor-default/src/test/java/com/alibaba/dubbo/monitor/dubbo/DubboMonitorFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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 com.alibaba.dubbo.monitor.dubbo; | ||
|
||
import com.alibaba.dubbo.common.Constants; | ||
import com.alibaba.dubbo.common.URL; | ||
import com.alibaba.dubbo.monitor.Monitor; | ||
import com.alibaba.dubbo.rpc.Invoker; | ||
import com.alibaba.dubbo.rpc.ProxyFactory; | ||
import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mock; | ||
|
||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.nullValue; | ||
import static org.hamcrest.Matchers.not; | ||
import static org.junit.Assert.assertThat; | ||
import static org.mockito.Mockito.atLeastOnce; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.MockitoAnnotations.initMocks; | ||
|
||
public class DubboMonitorFactoryTest { | ||
private DubboMonitorFactory dubboMonitorFactory; | ||
@Mock | ||
private ProxyFactory proxyFactory; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
initMocks(this); | ||
this.dubboMonitorFactory = new DubboMonitorFactory(); | ||
this.dubboMonitorFactory.setProtocol(new DubboProtocol()); | ||
this.dubboMonitorFactory.setProxyFactory(proxyFactory); | ||
} | ||
|
||
@Test | ||
public void testCreateMonitor() { | ||
URL urlWithoutPath = URL.valueOf("http://10.10.10.11"); | ||
Monitor monitor = dubboMonitorFactory.createMonitor(urlWithoutPath); | ||
assertThat(monitor, not(nullValue())); | ||
|
||
URL urlWithFilterKey = URL.valueOf("http://10.10.10.11/").addParameter(Constants.REFERENCE_FILTER_KEY, "testFilter"); | ||
monitor = dubboMonitorFactory.createMonitor(urlWithFilterKey); | ||
|
||
assertThat(monitor, not(nullValue())); | ||
ArgumentCaptor<Invoker> invokerArgumentCaptor = ArgumentCaptor.forClass(Invoker.class); | ||
verify(proxyFactory, atLeastOnce()).getProxy(invokerArgumentCaptor.capture()); | ||
|
||
Invoker invoker = invokerArgumentCaptor.getValue(); | ||
assertThat(invoker.getUrl().getParameter(Constants.REFERENCE_FILTER_KEY), containsString("testFilter")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...r/dubbo-monitor-default/src/test/java/com/alibaba/dubbo/monitor/dubbo/StatisticsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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 com.alibaba.dubbo.monitor.dubbo; | ||
|
||
import com.alibaba.dubbo.common.URL; | ||
import com.alibaba.dubbo.monitor.MonitorService; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
public class StatisticsTest { | ||
@Test | ||
public void testEquals() { | ||
URL statistics = new URL("dubbo", "10.20.153.10", 0) | ||
.addParameter(MonitorService.APPLICATION, "morgan") | ||
.addParameter(MonitorService.INTERFACE, "MemberService") | ||
.addParameter(MonitorService.METHOD, "findPerson") | ||
.addParameter(MonitorService.CONSUMER, "10.20.153.11") | ||
.addParameter(MonitorService.SUCCESS, 1) | ||
.addParameter(MonitorService.FAILURE, 0) | ||
.addParameter(MonitorService.ELAPSED, 3) | ||
.addParameter(MonitorService.MAX_ELAPSED, 3) | ||
.addParameter(MonitorService.CONCURRENT, 1) | ||
.addParameter(MonitorService.MAX_CONCURRENT, 1); | ||
|
||
Statistics statistics1 = new Statistics(statistics); | ||
Statistics statistics2 = new Statistics(statistics); | ||
|
||
Assert.assertThat(statistics1, equalTo(statistics1)); | ||
Assert.assertThat(statistics1, equalTo(statistics2)); | ||
|
||
statistics1.setVersion("2"); | ||
Assert.assertThat(statistics1, not(equalTo(statistics2))); | ||
Assert.assertThat(statistics1.hashCode(), not(equalTo(statistics2.hashCode()))); | ||
|
||
statistics1.setMethod("anotherMethod"); | ||
Assert.assertThat(statistics1, not(equalTo(statistics2))); | ||
Assert.assertThat(statistics1.hashCode(), not(equalTo(statistics2.hashCode()))); | ||
|
||
statistics1.setClient("anotherClient"); | ||
Assert.assertThat(statistics1, not(equalTo(statistics2))); | ||
Assert.assertThat(statistics1.hashCode(), not(equalTo(statistics2.hashCode()))); | ||
} | ||
|
||
@Test | ||
public void testToString() { | ||
Statistics statistics = new Statistics(new URL("dubbo", "10.20.153.10", 0)); | ||
statistics.setApplication("demo"); | ||
statistics.setMethod("findPerson"); | ||
statistics.setServer("10.20.153.10"); | ||
statistics.setGroup("unit-test"); | ||
statistics.setService("MemberService"); | ||
assertThat(statistics.toString(), is("dubbo://10.20.153.10")); | ||
|
||
Statistics statisticsWithDetailInfo = new Statistics(new URL("dubbo", "10.20.153.10", 0) | ||
.addParameter(MonitorService.APPLICATION, "morgan") | ||
.addParameter(MonitorService.INTERFACE, "MemberService") | ||
.addParameter(MonitorService.METHOD, "findPerson") | ||
.addParameter(MonitorService.CONSUMER, "10.20.153.11") | ||
.addParameter(MonitorService.GROUP, "unit-test") | ||
.addParameter(MonitorService.SUCCESS, 1) | ||
.addParameter(MonitorService.FAILURE, 0) | ||
.addParameter(MonitorService.ELAPSED, 3) | ||
.addParameter(MonitorService.MAX_ELAPSED, 3) | ||
.addParameter(MonitorService.CONCURRENT, 1) | ||
.addParameter(MonitorService.MAX_CONCURRENT, 1)); | ||
|
||
Assert.assertThat(statisticsWithDetailInfo.getServer(), equalTo(statistics.getServer())); | ||
Assert.assertThat(statisticsWithDetailInfo.getService(), equalTo(statistics.getService())); | ||
Assert.assertThat(statisticsWithDetailInfo.getMethod(), equalTo(statistics.getMethod())); | ||
|
||
Assert.assertThat(statisticsWithDetailInfo.getGroup(), equalTo(statistics.getGroup())); | ||
Assert.assertThat(statisticsWithDetailInfo, not(equalTo(statistics))); | ||
} | ||
} |