use of com.alibaba.csp.sentinel.slotchain.ProcessorSlot in project Sentinel by alibaba.
the class SpiLoaderTest method testLoadLowestPriorityInstance.
@Test
public void testLoadLowestPriorityInstance() {
ProcessorSlot slot = SpiLoader.of(ProcessorSlot.class).loadLowestPriorityInstance();
assertNotNull(slot);
// NodeSelectorSlot is lowest order priority with @Spi(order = -1000) among all slots
assertTrue(slot instanceof DegradeSlot);
}
use of com.alibaba.csp.sentinel.slotchain.ProcessorSlot 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);
}
use of com.alibaba.csp.sentinel.slotchain.ProcessorSlot 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);
}
use of com.alibaba.csp.sentinel.slotchain.ProcessorSlot in project Sentinel by alibaba.
the class DefaultSlotChainBuilder method build.
@Override
public ProcessorSlotChain build() {
ProcessorSlotChain chain = new DefaultProcessorSlotChain();
List<ProcessorSlot> sortedSlotList = SpiLoader.of(ProcessorSlot.class).loadInstanceListSorted();
for (ProcessorSlot slot : sortedSlotList) {
if (!(slot instanceof AbstractLinkedProcessorSlot)) {
RecordLog.warn("The ProcessorSlot(" + slot.getClass().getCanonicalName() + ") is not an instance of AbstractLinkedProcessorSlot, can't be added into ProcessorSlotChain");
continue;
}
chain.addLast((AbstractLinkedProcessorSlot<?>) slot);
}
return chain;
}
use of com.alibaba.csp.sentinel.slotchain.ProcessorSlot in project Sentinel by alibaba.
the class SpiLoaderTest method testLoadInstanceList.
@Test
public void testLoadInstanceList() {
SpiLoader spiLoader = SpiLoader.of(ProcessorSlot.class);
List<ProcessorSlot> slots1 = spiLoader.loadInstanceList();
List<ProcessorSlot> slots2 = spiLoader.loadInstanceList();
assertNotSame(slots1, slots2);
List<Class<? extends ProcessorSlot>> prototypeSlotClasses = new ArrayList<>(2);
prototypeSlotClasses.add(NodeSelectorSlot.class);
prototypeSlotClasses.add(ClusterBuilderSlot.class);
List<Class<? extends ProcessorSlot>> singletonSlotClasses = new ArrayList<>(6);
singletonSlotClasses.add(LogSlot.class);
singletonSlotClasses.add(StatisticSlot.class);
singletonSlotClasses.add(AuthoritySlot.class);
singletonSlotClasses.add(SystemSlot.class);
singletonSlotClasses.add(FlowSlot.class);
singletonSlotClasses.add(DegradeSlot.class);
for (int i = 0; i < slots1.size(); i++) {
ProcessorSlot slot1 = slots1.get(i);
ProcessorSlot slot2 = slots2.get(i);
assertSame(slot1.getClass(), slot2.getClass());
boolean found = false;
for (Class<? extends ProcessorSlot> prototypeSlotClass : prototypeSlotClasses) {
if (prototypeSlotClass.equals(slot1.getClass())) {
found = true;
assertTrue(prototypeSlotClass.equals(slot2.getClass()));
// Verify prototype function
assertNotSame(slot1, slot2);
break;
}
}
if (found) {
continue;
}
for (Class<? extends ProcessorSlot> singletonSlotClass : singletonSlotClasses) {
if (singletonSlotClass.equals(slot1.getClass())) {
found = true;
assertTrue(singletonSlotClass.equals(slot2.getClass()));
// Verify single function
assertSame(slot1, slot2);
break;
}
}
if (!found) {
fail("Should found and not go through here");
}
}
}
Aggregations