Signed-off-by: Eric Zhao <sczyh16@gmail.com>master
@@ -47,4 +47,12 @@ public class StringResourceWrapper extends ResourceWrapper { | |||||
public EntryType getType() { | public EntryType getType() { | ||||
return type; | return type; | ||||
} | } | ||||
@Override | |||||
public String toString() { | |||||
return "StringResourceWrapper{" + | |||||
"name='" + name + '\'' + | |||||
", type=" + type + | |||||
'}'; | |||||
} | |||||
} | } |
@@ -20,9 +20,9 @@ import java.util.concurrent.ExecutorService; | |||||
import java.util.concurrent.Executors; | import java.util.concurrent.Executors; | ||||
import java.util.concurrent.TimeUnit; | import java.util.concurrent.TimeUnit; | ||||
import com.alibaba.csp.sentinel.context.ContextTestUtil; | |||||
import com.alibaba.csp.sentinel.context.ContextUtil; | import com.alibaba.csp.sentinel.context.ContextUtil; | ||||
import com.alibaba.csp.sentinel.node.DefaultNode; | import com.alibaba.csp.sentinel.node.DefaultNode; | ||||
import com.alibaba.csp.sentinel.node.EntranceNode; | |||||
import com.alibaba.csp.sentinel.node.Node; | import com.alibaba.csp.sentinel.node.Node; | ||||
import com.alibaba.csp.sentinel.slots.block.BlockException; | import com.alibaba.csp.sentinel.slots.block.BlockException; | ||||
@@ -41,10 +41,7 @@ public class AsyncEntryIntegrationTest { | |||||
@Before | @Before | ||||
public void clearContext() { | public void clearContext() { | ||||
if (ContextUtil.getContext() != null) { | |||||
ContextUtil.getContext().setCurEntry(null); | |||||
ContextUtil.exit(); | |||||
} | |||||
ContextTestUtil.cleanUpContext(); | |||||
} | } | ||||
private final ExecutorService pool = Executors.newFixedThreadPool(10); | private final ExecutorService pool = Executors.newFixedThreadPool(10); | ||||
@@ -13,15 +13,18 @@ | |||||
* See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
* limitations under the License. | * limitations under the License. | ||||
*/ | */ | ||||
package com.alibaba.csp.sentinel; | |||||
package com.alibaba.csp.sentinel.context; | |||||
import com.alibaba.csp.sentinel.context.Context; | |||||
import com.alibaba.csp.sentinel.context.ContextUtil; | |||||
import com.alibaba.csp.sentinel.Constants; | |||||
/** | /** | ||||
* Util class for testing context-related functions. | |||||
* Only for test. DO NOT USE IN PRODUCTION! | |||||
* | |||||
* @author Eric Zhao | * @author Eric Zhao | ||||
* @since 0.2.0 | |||||
*/ | */ | ||||
public final class TestUtil { | |||||
public final class ContextTestUtil { | |||||
public static void cleanUpContext() { | public static void cleanUpContext() { | ||||
Context context = ContextUtil.getContext(); | Context context = ContextUtil.getContext(); | ||||
@@ -31,5 +34,10 @@ public final class TestUtil { | |||||
} | } | ||||
} | } | ||||
private TestUtil() {} | |||||
public static void resetContextMap() { | |||||
ContextUtil.resetContextMap(); | |||||
Constants.ROOT.removeChildList(); | |||||
} | |||||
private ContextTestUtil() {} | |||||
} | } |
@@ -1,6 +1,6 @@ | |||||
package com.alibaba.csp.sentinel.slots.block.authority; | package com.alibaba.csp.sentinel.slots.block.authority; | ||||
import com.alibaba.csp.sentinel.TestUtil; | |||||
import com.alibaba.csp.sentinel.context.ContextTestUtil; | |||||
import com.alibaba.csp.sentinel.context.ContextUtil; | import com.alibaba.csp.sentinel.context.ContextUtil; | ||||
import com.alibaba.csp.sentinel.slots.block.RuleConstant; | import com.alibaba.csp.sentinel.slots.block.RuleConstant; | ||||
@@ -18,7 +18,7 @@ public class AuthorityRuleCheckerTest { | |||||
@Before | @Before | ||||
public void setUp() { | public void setUp() { | ||||
TestUtil.cleanUpContext(); | |||||
ContextTestUtil.cleanUpContext(); | |||||
} | } | ||||
@Test | @Test | ||||
@@ -3,7 +3,7 @@ package com.alibaba.csp.sentinel.slots.block.authority; | |||||
import java.util.Collections; | import java.util.Collections; | ||||
import com.alibaba.csp.sentinel.EntryType; | import com.alibaba.csp.sentinel.EntryType; | ||||
import com.alibaba.csp.sentinel.TestUtil; | |||||
import com.alibaba.csp.sentinel.context.ContextTestUtil; | |||||
import com.alibaba.csp.sentinel.context.ContextUtil; | import com.alibaba.csp.sentinel.context.ContextUtil; | ||||
import com.alibaba.csp.sentinel.slotchain.ResourceWrapper; | import com.alibaba.csp.sentinel.slotchain.ResourceWrapper; | ||||
import com.alibaba.csp.sentinel.slotchain.StringResourceWrapper; | import com.alibaba.csp.sentinel.slotchain.StringResourceWrapper; | ||||
@@ -120,13 +120,13 @@ public class AuthoritySlotTest { | |||||
@Before | @Before | ||||
public void setUp() { | public void setUp() { | ||||
TestUtil.cleanUpContext(); | |||||
ContextTestUtil.cleanUpContext(); | |||||
AuthorityRuleManager.loadRules(null); | AuthorityRuleManager.loadRules(null); | ||||
} | } | ||||
@After | @After | ||||
public void tearDown() { | public void tearDown() { | ||||
TestUtil.cleanUpContext(); | |||||
ContextTestUtil.cleanUpContext(); | |||||
AuthorityRuleManager.loadRules(null); | AuthorityRuleManager.loadRules(null); | ||||
} | } | ||||
} | } |