Search in sources :

Example 1 with NodeSelectorSlot

use of com.alibaba.csp.sentinel.slots.nodeselector.NodeSelectorSlot in project Sentinel by alibaba.

the class DefaultSlotChainBuilderTest method testBuild.

@Test
public void testBuild() {
    DefaultSlotChainBuilder builder = new DefaultSlotChainBuilder();
    ProcessorSlotChain slotChain = builder.build();
    assertNotNull(slotChain);
    // Verify the order of slot
    AbstractLinkedProcessorSlot<?> next = slotChain.getNext();
    assertTrue(next instanceof NodeSelectorSlot);
    // Store the first NodeSelectorSlot instance
    NodeSelectorSlot nodeSelectorSlot = (NodeSelectorSlot) next;
    next = next.getNext();
    assertTrue(next instanceof ClusterBuilderSlot);
    next = next.getNext();
    assertTrue(next instanceof LogSlot);
    next = next.getNext();
    assertTrue(next instanceof StatisticSlot);
    next = next.getNext();
    assertTrue(next instanceof AuthoritySlot);
    next = next.getNext();
    assertTrue(next instanceof SystemSlot);
    next = next.getNext();
    assertTrue(next instanceof FlowSlot);
    next = next.getNext();
    assertTrue(next instanceof DegradeSlot);
    next = next.getNext();
    assertNull(next);
    // Build again to verify different instances
    ProcessorSlotChain slotChain2 = builder.build();
    assertNotNull(slotChain2);
    // Verify the two ProcessorSlotChain instances are different
    assertNotSame(slotChain, slotChain2);
    next = slotChain2.getNext();
    assertTrue(next instanceof NodeSelectorSlot);
    // Store the second NodeSelectorSlot instance
    NodeSelectorSlot nodeSelectorSlot2 = (NodeSelectorSlot) next;
    // Verify the two NodeSelectorSlot instances are different
    assertNotSame(nodeSelectorSlot, nodeSelectorSlot2);
}
Also used : ClusterBuilderSlot(com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot) ProcessorSlotChain(com.alibaba.csp.sentinel.slotchain.ProcessorSlotChain) LogSlot(com.alibaba.csp.sentinel.slots.logger.LogSlot) StatisticSlot(com.alibaba.csp.sentinel.slots.statistic.StatisticSlot) NodeSelectorSlot(com.alibaba.csp.sentinel.slots.nodeselector.NodeSelectorSlot) DegradeSlot(com.alibaba.csp.sentinel.slots.block.degrade.DegradeSlot) FlowSlot(com.alibaba.csp.sentinel.slots.block.flow.FlowSlot) AuthoritySlot(com.alibaba.csp.sentinel.slots.block.authority.AuthoritySlot) SystemSlot(com.alibaba.csp.sentinel.slots.system.SystemSlot) Test(org.junit.Test)

Example 2 with NodeSelectorSlot

use of com.alibaba.csp.sentinel.slots.nodeselector.NodeSelectorSlot in project Sentinel by alibaba.

the class SpiLoaderTest method testLoadHighestPriorityInstance.

@Test
public void testLoadHighestPriorityInstance() {
    ProcessorSlot slot = SpiLoader.of(ProcessorSlot.class).loadHighestPriorityInstance();
    assertNotNull(slot);
    // NodeSelectorSlot is highest order priority with @Spi(order = -10000) among all slots
    assertTrue(slot instanceof NodeSelectorSlot);
}
Also used : ProcessorSlot(com.alibaba.csp.sentinel.slotchain.ProcessorSlot) NodeSelectorSlot(com.alibaba.csp.sentinel.slots.nodeselector.NodeSelectorSlot) Test(org.junit.Test)

Example 3 with NodeSelectorSlot

use of com.alibaba.csp.sentinel.slots.nodeselector.NodeSelectorSlot in project Sentinel by alibaba.

the class SpiLoaderTest method testLoadFirstInstance.

@Test
public void testLoadFirstInstance() {
    ProcessorSlot slot = SpiLoader.of(ProcessorSlot.class).loadFirstInstance();
    assertNotNull(slot);
    assertTrue(slot instanceof NodeSelectorSlot);
    SlotChainBuilder chainBuilder = SpiLoader.of(SlotChainBuilder.class).loadFirstInstance();
    assertNotNull(chainBuilder);
    assertTrue(chainBuilder instanceof SlotChainBuilder);
    InitFunc initFunc = SpiLoader.of(InitFunc.class).loadFirstInstance();
    assertNotNull(initFunc);
    assertTrue(initFunc instanceof MetricCallbackInit);
}
Also used : InitFunc(com.alibaba.csp.sentinel.init.InitFunc) SlotChainBuilder(com.alibaba.csp.sentinel.slotchain.SlotChainBuilder) DefaultSlotChainBuilder(com.alibaba.csp.sentinel.slots.DefaultSlotChainBuilder) MetricCallbackInit(com.alibaba.csp.sentinel.metric.extension.MetricCallbackInit) ProcessorSlot(com.alibaba.csp.sentinel.slotchain.ProcessorSlot) NodeSelectorSlot(com.alibaba.csp.sentinel.slots.nodeselector.NodeSelectorSlot) Test(org.junit.Test)

Aggregations

NodeSelectorSlot (com.alibaba.csp.sentinel.slots.nodeselector.NodeSelectorSlot)3 Test (org.junit.Test)3 ProcessorSlot (com.alibaba.csp.sentinel.slotchain.ProcessorSlot)2 InitFunc (com.alibaba.csp.sentinel.init.InitFunc)1 MetricCallbackInit (com.alibaba.csp.sentinel.metric.extension.MetricCallbackInit)1 ProcessorSlotChain (com.alibaba.csp.sentinel.slotchain.ProcessorSlotChain)1 SlotChainBuilder (com.alibaba.csp.sentinel.slotchain.SlotChainBuilder)1 DefaultSlotChainBuilder (com.alibaba.csp.sentinel.slots.DefaultSlotChainBuilder)1 AuthoritySlot (com.alibaba.csp.sentinel.slots.block.authority.AuthoritySlot)1 DegradeSlot (com.alibaba.csp.sentinel.slots.block.degrade.DegradeSlot)1 FlowSlot (com.alibaba.csp.sentinel.slots.block.flow.FlowSlot)1 ClusterBuilderSlot (com.alibaba.csp.sentinel.slots.clusterbuilder.ClusterBuilderSlot)1 LogSlot (com.alibaba.csp.sentinel.slots.logger.LogSlot)1 StatisticSlot (com.alibaba.csp.sentinel.slots.statistic.StatisticSlot)1 SystemSlot (com.alibaba.csp.sentinel.slots.system.SystemSlot)1