test: Fix overrunning test `FlowRuleManagerTest.testLoadAndGetRules` (#1823)
Signed-off-by: Jason Joo <hblzxsj@163.com>
This commit is contained in:
parent
c00f946813
commit
d510eb6cd3
|
|
@ -116,15 +116,16 @@ public class FlowPartialIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void testOriginFlowRule() {
|
||||
String RESOURCE_NAME = "testOriginFlowRule";
|
||||
// normal
|
||||
FlowRule flowRule = new FlowRule();
|
||||
flowRule.setResource("testOriginFlowRule");
|
||||
flowRule.setResource(RESOURCE_NAME);
|
||||
flowRule.setGrade(RuleConstant.FLOW_GRADE_QPS);
|
||||
flowRule.setCount(0);
|
||||
flowRule.setLimitApp("other");
|
||||
|
||||
FlowRule flowRule2 = new FlowRule();
|
||||
flowRule2.setResource("testOriginFlowRule");
|
||||
flowRule2.setResource(RESOURCE_NAME);
|
||||
flowRule2.setGrade(RuleConstant.FLOW_GRADE_QPS);
|
||||
flowRule2.setCount(1);
|
||||
flowRule2.setLimitApp("app2");
|
||||
|
|
@ -134,7 +135,7 @@ public class FlowPartialIntegrationTest {
|
|||
ContextUtil.enter("node1", "app1");
|
||||
Entry e = null;
|
||||
try {
|
||||
e = SphU.entry("testOriginFlowRule");
|
||||
e = SphU.entry(RESOURCE_NAME);
|
||||
fail("Should had failed");
|
||||
} catch (BlockException e1) {
|
||||
e1.printStackTrace();
|
||||
|
|
@ -146,7 +147,7 @@ public class FlowPartialIntegrationTest {
|
|||
ContextUtil.enter("node1", "app2");
|
||||
e = null;
|
||||
try {
|
||||
e = SphU.entry("testOriginFlowRule");
|
||||
e = SphU.entry(RESOURCE_NAME);
|
||||
} catch (BlockException e1) {
|
||||
fail("Should had failed");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import org.junit.Test;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
|
@ -44,27 +46,34 @@ public class FlowRuleManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testLoadAndGetRules(){
|
||||
public void testLoadAndGetRules() throws InterruptedException{
|
||||
FlowRuleManager.loadRules(STATIC_RULES_1);
|
||||
assertEquals(1, FlowRuleManager.getRules().size()); // the initial size
|
||||
new Thread(loader, "Loader").start();
|
||||
final CountDownLatch latchStart = new CountDownLatch(1);
|
||||
final CountDownLatch latchEnd = new CountDownLatch(1);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
latchStart.await(10, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
for(int i = 0; i < 10000; i++){
|
||||
//to guarantee that they're different and change happens
|
||||
FlowRuleManager.loadRules(i % 2 == 0 ? STATIC_RULES_2 : STATIC_RULES_1);
|
||||
}
|
||||
latchEnd.countDown();
|
||||
}
|
||||
}).start();
|
||||
|
||||
for(int i = 0; i < 10000; i++){
|
||||
latchStart.countDown();
|
||||
for (int i = 0; i < 10000; i++) {
|
||||
//The initial size is 1, and the size after updating should also be 1,
|
||||
//if the actual size is 0, that must be called after clear(),
|
||||
// but before putAll() in FlowPropertyListener.configUpdate
|
||||
assertEquals(1, FlowRuleManager.getRules().size());
|
||||
}
|
||||
latchEnd.await(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public Runnable loader = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for(int i = 0; i < 10000; i++){
|
||||
//to guarantee that they're different and change happens
|
||||
FlowRuleManager.loadRules(i % 2 == 0 ? STATIC_RULES_2 : STATIC_RULES_1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import org.junit.After;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue