Browse Source

Some code update and rearrangement

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao 6 years ago
parent
commit
fe6b4f4865
6 changed files with 28 additions and 15 deletions
  1. +8
    -0
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slotchain/StringResourceWrapper.java
  2. +0
    -0
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/Striped64.java
  3. +2
    -5
      sentinel-core/src/test/java/com/alibaba/csp/sentinel/AsyncEntryIntegrationTest.java
  4. +13
    -5
      sentinel-core/src/test/java/com/alibaba/csp/sentinel/context/ContextTestUtil.java
  5. +2
    -2
      sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleCheckerTest.java
  6. +3
    -3
      sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/authority/AuthoritySlotTest.java

+ 8
- 0
sentinel-core/src/main/java/com/alibaba/csp/sentinel/slotchain/StringResourceWrapper.java View File

@@ -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 +
'}';
}
} }

sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/Stripe64.java → sentinel-core/src/main/java/com/alibaba/csp/sentinel/slots/statistic/base/Striped64.java View File


+ 2
- 5
sentinel-core/src/test/java/com/alibaba/csp/sentinel/AsyncEntryIntegrationTest.java View File

@@ -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);


sentinel-core/src/test/java/com/alibaba/csp/sentinel/TestUtil.java → sentinel-core/src/test/java/com/alibaba/csp/sentinel/context/ContextTestUtil.java View File

@@ -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() {}
} }

+ 2
- 2
sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/authority/AuthorityRuleCheckerTest.java View File

@@ -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
- 3
sentinel-core/src/test/java/com/alibaba/csp/sentinel/slots/block/authority/AuthoritySlotTest.java View File

@@ -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);
} }
} }

Loading…
Cancel
Save