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