Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Ut/bootstrap api #1163

Merged
merged 4 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.3.0</version>
<version>4.3.0</version>
<scope>test</scope>
</dependency>
<!-- h2 SSL libs -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testGetDynamicAttr() {
public void testGetWeight() {
//1s
ProviderInfo provider = ProviderHelper
.toProviderInfo("bolt://10.15.232.229:12222?timeout=3333&serialization=hessian2&connections=1&warmupTime=1000&warmupWeight=5&appName=test-server&weight=2000");
.toProviderInfo("bolt://10.15.232.229:12222?timeout=3333&serialization=hessian2&connections=1&warmupTime=100&warmupWeight=5&appName=test-server&weight=2000");

long warmupTime = Long.parseLong(provider.getStaticAttr(ProviderInfoAttrs.ATTR_WARMUP_TIME));
provider.setDynamicAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT,
Expand All @@ -71,11 +71,11 @@ public void testGetWeight() {
Assert.assertEquals(5, provider.getDynamicAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT));
Assert.assertTrue(provider.getDynamicAttr(ProviderInfoAttrs.ATTR_WARM_UP_END_TIME) != null);
Assert.assertEquals("5", provider.getStaticAttr(ProviderInfoAttrs.ATTR_WARMUP_WEIGHT));
Assert.assertEquals("1000", provider.getStaticAttr(ProviderInfoAttrs.ATTR_WARMUP_TIME));
Assert.assertEquals("100", provider.getStaticAttr(ProviderInfoAttrs.ATTR_WARMUP_TIME));
Assert.assertEquals(ProviderStatus.WARMING_UP, provider.getStatus());
Assert.assertEquals(5, provider.getWeight());
try {
TimeUnit.SECONDS.sleep(2);
TimeUnit.MILLISECONDS.sleep(200);
} catch (Exception ignored) {
}
Assert.assertTrue(provider.getWeight() == 2000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,42 @@ public class TimeWaitLoggerTest {

@Test
public void testTimeWait() throws InterruptedException {
TimeWaitLogger timeWaitLogger = new TimeWaitLogger(1000);
TimeWaitLogger timeWaitLogger = new TimeWaitLogger(100);
AtomicLong atomicLong = new AtomicLong();
new Thread(()->{
while (true){
timeWaitLogger.logWithRunnable(atomicLong::incrementAndGet);
}
}).start();
Thread.sleep(1500);
Thread.sleep(150);
Assert.assertEquals(2L,atomicLong.get());
}

@Test
public void testDisable() throws InterruptedException {
System.setProperty(RpcOptions.DISABLE_LOG_TIME_WAIT_CONF,"true");
try{
TimeWaitLogger timeWaitLogger = new TimeWaitLogger(1000);
TimeWaitLogger timeWaitLogger = new TimeWaitLogger(100);
AtomicLong atomicLong = new AtomicLong();
new Thread(()->{
while (true){
timeWaitLogger.logWithRunnable(atomicLong::incrementAndGet);
}
}).start();
Thread.sleep(1500);
Thread.sleep(150);
Assert.assertTrue(atomicLong.get()>1000);
}finally {
System.setProperty(RpcOptions.DISABLE_LOG_TIME_WAIT_CONF,"");
}

TimeWaitLogger timeWaitLogger = new TimeWaitLogger(1000);
TimeWaitLogger timeWaitLogger = new TimeWaitLogger(100);
AtomicLong atomicLong = new AtomicLong();
new Thread(()->{
while (true){
timeWaitLogger.logWithRunnable(atomicLong::incrementAndGet);
}
}).start();
Thread.sleep(1500);
Thread.sleep(150);
Assert.assertEquals(2L,atomicLong.get());

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.alipay.sofa.rpc.std;

import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

/**
* @author zhaowang
* @version : AbstractMockitoTest.java, v 0.1 2022年01月25日 4:02 下午 zhaowang
*/
@RunWith(MockitoJUnitRunner.Strict.class)
public abstract class AbstractMockitoTest {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.alipay.sofa.rpc.std.config;

import com.alipay.sofa.rpc.common.utils.TestUtils;
import com.alipay.sofa.rpc.config.AbstractIdConfig;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* @author zhaowang
* @version : AbstractIdConfigTest.java, v 0.1 2022年01月25日 4:53 下午 zhaowang
*/
public class AbstractIdConfigTest {

@Test
public void testDefaultValue() {
TestConfig defaultConfig = new TestConfig();
assertTrue(defaultConfig.getId().startsWith("rpc-cfg-"));
}

@Test
public void testSetMethod() {
String id = TestUtils.randomString();
TestConfig testConfig = new TestConfig();
testConfig.setId(id);
assertEquals(id, testConfig.getId());
}

static class TestConfig extends AbstractIdConfig {
}

}
Loading