mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-27 21:26:17 +01:00
Add a timeout to server startup and the ping test.
This commit is contained in:
parent
09cc024a3f
commit
c058498267
@ -7,6 +7,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
@ -29,6 +31,14 @@ public class SimpleCraftBukkitITCase {
|
||||
// The fake plugin
|
||||
private static volatile Plugin FAKE_PLUGIN = null;
|
||||
|
||||
/**
|
||||
* The maximum amount of time to wait before a server has started.
|
||||
* <p>
|
||||
* We have to give it the ample time of 60 seconds, as a server may have to
|
||||
* generate the spawn area in three worlds.
|
||||
*/
|
||||
private static final int TIMEOUT_MS = 60000;
|
||||
|
||||
/**
|
||||
* Setup the CraftBukkit server for all the tests.
|
||||
* @throws IOException Unable to setup server.
|
||||
@ -55,7 +65,7 @@ public class SimpleCraftBukkitITCase {
|
||||
public Object call() throws Exception {
|
||||
return null;
|
||||
}
|
||||
}).get();
|
||||
}).get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
|
||||
|
||||
// Plugins are now ready
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
@ -22,6 +23,9 @@ public class TestPingPacket {
|
||||
private static final String CRAFTBUKKIT_VERSION = "1.6.2";
|
||||
private static final int PROTOCOL_VERSION = 74;
|
||||
|
||||
// Timeout
|
||||
private static final int TIMEOUT_PING_MS = 10000;
|
||||
|
||||
private volatile String source;
|
||||
|
||||
private TestPingPacket() {
|
||||
@ -43,7 +47,8 @@ public class TestPingPacket {
|
||||
*/
|
||||
public void startTest(Plugin plugin) throws Throwable {
|
||||
try {
|
||||
String transmitted = testInterception(plugin).get();
|
||||
String transmitted = testInterception(plugin).
|
||||
get(TIMEOUT_PING_MS, TimeUnit.MILLISECONDS);
|
||||
|
||||
// Make sure it's the same
|
||||
System.out.println("Server string: " + transmitted);
|
||||
@ -66,7 +71,8 @@ public class TestPingPacket {
|
||||
return Executors.newSingleThreadExecutor().submit(new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
SimpleMinecraftClient client = new SimpleMinecraftClient(new MinecraftVersion(CRAFTBUKKIT_VERSION), PROTOCOL_VERSION);
|
||||
SimpleMinecraftClient client = new SimpleMinecraftClient(
|
||||
new MinecraftVersion(CRAFTBUKKIT_VERSION), PROTOCOL_VERSION);
|
||||
String information = client.queryLocalPing();
|
||||
|
||||
// Wait for the listener to catch up
|
||||
|
Loading…
Reference in New Issue
Block a user