From fe6b4f4865e8611e6ebe14fbee5c7f141c9918c0 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Thu, 20 Sep 2018 23:22:52 +0800 Subject: [PATCH] Some code update and rearrangement Signed-off-by: Eric Zhao --- .../slotchain/StringResourceWrapper.java | 8 ++++++++ .../base/{Stripe64.java => Striped64.java} | 0 .../sentinel/AsyncEntryIntegrationTest.java | 7 ++----- .../ContextTestUtil.java} | 18 +++++++++++++----- .../authority/AuthorityRuleCheckerTest.java | 4 ++-- .../block/authority/AuthoritySlotTest.java | 6 +++--- 6 files changed, 28 insertions(+), 15 deletions(-) rename sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/{Stripe64.java => Striped64.java} (100%) rename sentinel-core/src/test/java/com/alibaba/csp/sentinel/{TestUtil.java => context/ContextTestUtil.java} (68%) diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slotchain/StringResourceWrapper.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slotchain/StringResourceWrapper.java index a9096356..d45f0882 100755 --- a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slotchain/StringResourceWrapper.java +++ b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slotchain/StringResourceWrapper.java @@ -47,4 +47,12 @@ public class StringResourceWrapper extends ResourceWrapper { public EntryType getType() { return type; } + + @Override + public String toString() { + return "StringResourceWrapper{" + + "name='" + name + '\'' + + ", type=" + type + + '}'; + } } diff --git a/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/Stripe64.java b/sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/Striped64.java similarity index 100% rename from sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/Stripe64.java rename to sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/Striped64.java diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/AsyncEntryIntegrationTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/AsyncEntryIntegrationTest.java index 589ac19a..b7de69ee 100644 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/AsyncEntryIntegrationTest.java +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/AsyncEntryIntegrationTest.java @@ -20,9 +20,9 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import com.alibaba.csp.sentinel.context.ContextTestUtil; import com.alibaba.csp.sentinel.context.ContextUtil; 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.slots.block.BlockException; @@ -41,10 +41,7 @@ public class AsyncEntryIntegrationTest { @Before public void clearContext() { - if (ContextUtil.getContext() != null) { - ContextUtil.getContext().setCurEntry(null); - ContextUtil.exit(); - } + ContextTestUtil.cleanUpContext(); } private final ExecutorService pool = Executors.newFixedThreadPool(10); diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/TestUtil.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/context/ContextTestUtil.java similarity index 68% rename from sentinel-core/src/test/java/com/alibaba/csp/sentinel/TestUtil.java rename to sentinel-core/src/test/java/com/alibaba/csp/sentinel/context/ContextTestUtil.java index 55604139..8ebcb4dd 100644 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/TestUtil.java +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/context/ContextTestUtil.java @@ -13,15 +13,18 @@ * See the License for the specific language governing permissions and * 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 + * @since 0.2.0 */ -public final class TestUtil { +public final class ContextTestUtil { public static void cleanUpContext() { 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() {} } diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleCheckerTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleCheckerTest.java index 537ee7f4..7f88447d 100644 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleCheckerTest.java +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleCheckerTest.java @@ -1,6 +1,6 @@ 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.slots.block.RuleConstant; @@ -18,7 +18,7 @@ public class AuthorityRuleCheckerTest { @Before public void setUp() { - TestUtil.cleanUpContext(); + ContextTestUtil.cleanUpContext(); } @Test diff --git a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/authority/AuthoritySlotTest.java b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/authority/AuthoritySlotTest.java index b04cbc5d..c17e25ad 100644 --- a/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/authority/AuthoritySlotTest.java +++ b/sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/authority/AuthoritySlotTest.java @@ -3,7 +3,7 @@ package com.alibaba.csp.sentinel.slots.block.authority; import java.util.Collections; 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.slotchain.ResourceWrapper; import com.alibaba.csp.sentinel.slotchain.StringResourceWrapper; @@ -120,13 +120,13 @@ public class AuthoritySlotTest { @Before public void setUp() { - TestUtil.cleanUpContext(); + ContextTestUtil.cleanUpContext(); AuthorityRuleManager.loadRules(null); } @After public void tearDown() { - TestUtil.cleanUpContext(); + ContextTestUtil.cleanUpContext(); AuthorityRuleManager.loadRules(null); } } \ No newline at end of file