Archiviert
13
0

Add a timeout to server startup and the ping test.

Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-10-07 05:16:20 +02:00
Ursprung 09cc024a3f
Commit c058498267
2 geänderte Dateien mit 19 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -7,6 +7,8 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -29,6 +31,14 @@ public class SimpleCraftBukkitITCase {
// The fake plugin // The fake plugin
private static volatile Plugin FAKE_PLUGIN = null; 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. * Setup the CraftBukkit server for all the tests.
* @throws IOException Unable to setup server. * @throws IOException Unable to setup server.
@ -55,7 +65,7 @@ public class SimpleCraftBukkitITCase {
public Object call() throws Exception { public Object call() throws Exception {
return null; return null;
} }
}).get(); }).get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
// Plugins are now ready // Plugins are now ready
} }

Datei anzeigen

@ -6,6 +6,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -22,6 +23,9 @@ public class TestPingPacket {
private static final String CRAFTBUKKIT_VERSION = "1.6.2"; private static final String CRAFTBUKKIT_VERSION = "1.6.2";
private static final int PROTOCOL_VERSION = 74; private static final int PROTOCOL_VERSION = 74;
// Timeout
private static final int TIMEOUT_PING_MS = 10000;
private volatile String source; private volatile String source;
private TestPingPacket() { private TestPingPacket() {
@ -43,7 +47,8 @@ public class TestPingPacket {
*/ */
public void startTest(Plugin plugin) throws Throwable { public void startTest(Plugin plugin) throws Throwable {
try { try {
String transmitted = testInterception(plugin).get(); String transmitted = testInterception(plugin).
get(TIMEOUT_PING_MS, TimeUnit.MILLISECONDS);
// Make sure it's the same // Make sure it's the same
System.out.println("Server string: " + transmitted); System.out.println("Server string: " + transmitted);
@ -66,7 +71,8 @@ public class TestPingPacket {
return Executors.newSingleThreadExecutor().submit(new Callable<String>() { return Executors.newSingleThreadExecutor().submit(new Callable<String>() {
@Override @Override
public String call() throws Exception { 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(); String information = client.queryLocalPing();
// Wait for the listener to catch up // Wait for the listener to catch up