Reorganized test cases
This commit is contained in:
@@ -12,6 +12,10 @@ import java.util.*;
|
|||||||
public class SimpleEventLoop extends BaseEventLoop {
|
public class SimpleEventLoop extends BaseEventLoop {
|
||||||
private Map<Class<? extends Event>, List<ExecutorLink>> handlers = new HashMap<>();
|
private Map<Class<? extends Event>, List<ExecutorLink>> handlers = new HashMap<>();
|
||||||
|
|
||||||
|
public SimpleEventLoop() {
|
||||||
|
log.warn("Warning! SimpleEventLoop doesn't support EventPreprocessors and DI. Code annotated @EventProcessor will not be executed at all.");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void callEvent(Event event) {
|
public void callEvent(Event event) {
|
||||||
Class<? extends Event> eventType = event.getClass();
|
Class<? extends Event> eventType = event.getClass();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package ru.core.events;
|
package ru.core.events;
|
||||||
|
|
||||||
import com.carrotsearch.junitbenchmarks.AbstractBenchmark;
|
import com.carrotsearch.junitbenchmarks.AbstractBenchmark;
|
||||||
|
import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
|
||||||
import mc.core.events.LoginEvent;
|
import mc.core.events.LoginEvent;
|
||||||
import mc.core.events.async.AdvancedEventLoop;
|
import mc.core.events.async.AdvancedEventLoop;
|
||||||
import mc.core.events.async.AsyncEventLoop;
|
import mc.core.events.async.AsyncEventLoop;
|
||||||
@@ -9,7 +10,7 @@ import org.junit.Test;
|
|||||||
import ru.core.events.handlers.AsyncEventHandler;
|
import ru.core.events.handlers.AsyncEventHandler;
|
||||||
|
|
||||||
public class AsyncEventLoopBenchmark extends AbstractBenchmark {
|
public class AsyncEventLoopBenchmark extends AbstractBenchmark {
|
||||||
private static final int ITERATIONS = 50_000;
|
private static final int ITERATIONS = 600;
|
||||||
private static AsyncEventLoop asyncEventLoop;
|
private static AsyncEventLoop asyncEventLoop;
|
||||||
private static AdvancedEventLoop advancedEventLoop;
|
private static AdvancedEventLoop advancedEventLoop;
|
||||||
private static LoginEvent testEvent;
|
private static LoginEvent testEvent;
|
||||||
@@ -25,28 +26,18 @@ public class AsyncEventLoopBenchmark extends AbstractBenchmark {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void measure() {
|
@BenchmarkOptions(warmupRounds = 5, benchmarkRounds = 15)
|
||||||
for (int i = 0; i < 10000; i++) {
|
public void async() {
|
||||||
|
for (int i = 0; i < ITERATIONS; i++) {
|
||||||
asyncEventLoop.callEvent(testEvent);
|
asyncEventLoop.callEvent(testEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @Test
|
|
||||||
@BenchmarkOptions(warmupRounds = 5, benchmarkRounds = 15)
|
|
||||||
public void async() {
|
|
||||||
while (true)
|
|
||||||
asyncEventLoop.callEvent(testEvent);
|
|
||||||
*//*for (int i = 0; i < ITERATIONS; i++) {
|
|
||||||
asyncEventLoop.callEvent(testEvent);
|
|
||||||
|
|
||||||
}*//*
|
|
||||||
}*/
|
|
||||||
/*
|
|
||||||
@Test
|
@Test
|
||||||
@BenchmarkOptions(warmupRounds = 5, benchmarkRounds = 15)
|
@BenchmarkOptions(warmupRounds = 5, benchmarkRounds = 15)
|
||||||
public void advanced() {
|
public void advanced() {
|
||||||
for (int i = 0; i < ITERATIONS; i++) {
|
for (int i = 0; i < ITERATIONS; i++) {
|
||||||
advancedEventLoop.callEvent(testEvent);
|
advancedEventLoop.callEvent(testEvent);
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,14 @@ import mc.core.events.LoginEvent;
|
|||||||
import mc.core.events.SimpleEventLoop;
|
import mc.core.events.SimpleEventLoop;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import ru.core.events.handlers.FastEventHandler;
|
import ru.core.events.handlers.HelloWorldSimpleEventHandler;
|
||||||
import ru.core.events.handlers.SampleEventHandler;
|
|
||||||
|
|
||||||
public class SimpleEventLoopTest {
|
public class SimpleEventLoopTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loopWorks() {
|
public void loopWorks() {
|
||||||
SimpleEventLoop simpleEventLoop = new SimpleEventLoop();
|
SimpleEventLoop simpleEventLoop = new SimpleEventLoop();
|
||||||
simpleEventLoop.addEventHandler(new FastEventHandler());
|
simpleEventLoop.addEventHandler(new HelloWorldSimpleEventHandler());
|
||||||
LoginEvent testEvent = new LoginEvent(null);
|
LoginEvent testEvent = new LoginEvent(null);
|
||||||
testEvent.setDenyReason("none");
|
testEvent.setDenyReason("none");
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,11 @@ public class AsyncEventHandler {
|
|||||||
public void onLoginPreprocess(LoginEvent event) {
|
public void onLoginPreprocess(LoginEvent event) {
|
||||||
event.setDenyReason("Hello! This is a message from Async event preprocessor.");
|
event.setDenyReason("Hello! This is a message from Async event preprocessor.");
|
||||||
|
|
||||||
|
try {
|
||||||
|
Thread.sleep(1);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
// Представим, что здесь мы выполнили запрос к БД
|
// Представим, что здесь мы выполнили запрос к БД
|
||||||
// и это значение - кол-во денег у игрока
|
// и это значение - кол-во денег у игрока
|
||||||
/*return 20D;*/
|
/*return 20D;*/
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package ru.core.events.handlers;
|
||||||
|
|
||||||
|
import mc.core.events.EventHandler;
|
||||||
|
import mc.core.events.LoginEvent;
|
||||||
|
|
||||||
|
public class HelloWorldSimpleEventHandler {
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerLogin(LoginEvent event) {
|
||||||
|
event.setDenyReason("Hello from SampleEventHandler!");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user