init: 仓库初始化.
This commit is contained in:
41
src/test/java/com/serliunx/statemanagement/MachineTest.java
Normal file
41
src/test/java/com/serliunx/statemanagement/MachineTest.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.serliunx.statemanagement;
|
||||
|
||||
import com.serliunx.statemanagement.machine.StateMachine;
|
||||
import com.serliunx.statemanagement.machine.StateMachineBuilder;
|
||||
import com.serliunx.statemanagement.support.PrinterState;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* 状态机测试
|
||||
*
|
||||
* @author <a href="mailto:serliunx@yeah.net">SerLiunx</a>
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/28
|
||||
*/
|
||||
@Slf4j
|
||||
public class MachineTest {
|
||||
|
||||
@Test
|
||||
public void testStandardStateMachine() {
|
||||
StateMachine<PrinterState> stateMachine = StateMachineBuilder.from(PrinterState.class)
|
||||
.async(false)
|
||||
.whenLeave(PrinterState.PRINTING, h -> {
|
||||
System.out.println(Thread.currentThread().getName() + ": leave PRINTING");
|
||||
})
|
||||
.states(PrinterState.values())
|
||||
.executor(Executors.newFixedThreadPool(16))
|
||||
.whenEntry(PrinterState.SCANNING, h -> {
|
||||
System.out.println(Thread.currentThread().getName() + ": " + h.getFrom() + " >>> " + h.getTo());
|
||||
}, false)
|
||||
.whenEntry(PrinterState.PRINTING, h -> {
|
||||
System.out.println(Thread.currentThread().getName() + ": " + h.getFrom() + " >>> " + h.getTo());
|
||||
}, false, Executors.newFixedThreadPool(1))
|
||||
.exchange(PrinterState.STOPPED, PrinterState.IDLE, h -> {
|
||||
System.out.println(Thread.currentThread().getName() + ": " + h.getFrom() + " >>> " + h.getTo());
|
||||
})
|
||||
.build();
|
||||
}
|
||||
}
|
||||
20
src/test/java/com/serliunx/statemanagement/ManagerTest.java
Normal file
20
src/test/java/com/serliunx/statemanagement/ManagerTest.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.serliunx.statemanagement;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 状态管理器测试
|
||||
*
|
||||
* @author <a href="mailto:serliunx@yeah.net">SerLiunx</a>
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/28
|
||||
*/
|
||||
@Slf4j
|
||||
public class ManagerTest {
|
||||
|
||||
@Test
|
||||
public void testUnidirectionalStateManager() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.serliunx.statemanagement.support;
|
||||
|
||||
/**
|
||||
* @author <a href="mailto:serliunx@yeah.net">SerLiunx</a>
|
||||
* @version 1.0.0
|
||||
* @since 2024/12/28
|
||||
*/
|
||||
public enum PrinterState {
|
||||
IDLE,
|
||||
SCANNING,
|
||||
PRINTING,
|
||||
STOPPING,
|
||||
STOPPED
|
||||
}
|
||||
Reference in New Issue
Block a user