// Path: server/src/main/java/com/threerings/nexus/distrib/Action.java
// public abstract class Action<E>
// {
//     /** A variant of {@link Action} that can be used when you know that the action will not cross
//      * server boundaries. This allows things to be referenced from the enclosing scope <em>when
//      * that is known to be thread safe</em>. Remember that actions likely execute in a different
//      * thread context than the one from which they were initiated, so one must be careful not to
//      * use things from an enclosing scope that will cause race conditions. */
//     public static abstract class Local<E> extends Action<E> {
//     }
// 
//     /**
//      * Called with the requested entity on the thread appropriate for said entity.
//      */
//     public abstract void invoke (E entity);
// 
//     /**
//      * Called if the action could not be processed due to the target entity being not found. Note:
//      * this only occurs for keyed entities, not singleton entities. Note also that this method will
//      * be called in no execution context, which means that one must either perform only thread-safe
//      * operations in the body of this method, or one must dispatch a new action to process the
//      * failure. The default implementation simply logs a warning.
//      *
//      * @param nexus a reference to the nexus for convenient dispatch of a new action.
//      * @param eclass the class of the entity that could not be found.
//      * @param key the key of the entity that could not be found.
//      */
//     public void onDropped (Nexus nexus, Class<?> eclass, Comparable<?> key) {
//         log.warning("Dropping action on unknown entity", "eclass", eclass.getName(), "key", key,
//                     "action", this);
//     }
// }
// 
// Path: core/src/main/java/com/threerings/nexus/distrib/Singleton.java
// public interface Singleton
// {
// }


import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import com.threerings.nexus.distrib.Action;
import com.threerings.nexus.distrib.Singleton;
//
// Nexus Server - server-side support for Nexus distributed application framework
// http://github.com/threerings/nexus/blob/master/LICENSE

package com.threerings.nexus.server;




public class NexusJavaTest
{
    @Before public void createServer () {
        System.setProperty("nexus.safety_checks", "true");
        _exec = Executors.newFixedThreadPool(3);
        Properties props = new Properties();
        props.setProperty("nexus.node", "test");
        props.setProperty("nexus.hostname", "localhost");
        props.setProperty("nexus.rpc_timeout", "1000");
        _server = new NexusServer(new NexusConfig(props), _exec);
    }

    @After public void shutdownServer () throws Exception {
        _server.shutdown();
        _exec.shutdown();
        if (!_exec.awaitTermination(2, TimeUnit.SECONDS)) {
            fail("Executor failed to terminate after 2 seconds.");
        }
        System.setProperty("nexus.safety_checks", "");
    }

    @Test public void testRuntimeChecksOnAction () {
        final boolean[] printed = new boolean[] { false };

// Path: server/src/main/java/com/threerings/nexus/distrib/Action.java
// public abstract class Action<E>
// {
//     /** A variant of {@link Action} that can be used when you know that the action will not cross
//      * server boundaries. This allows things to be referenced from the enclosing scope <em>when
//      * that is known to be thread safe</em>. Remember that actions likely execute in a different
//      * thread context than the one from which they were initiated, so one must be careful not to
//      * use things from an enclosing scope that will cause race conditions. */
//     public static abstract class Local<E> extends Action<E> {
//     }
// 
//     /**
//      * Called with the requested entity on the thread appropriate for said entity.
//      */
//     public abstract void invoke (E entity);
// 
//     /**
//      * Called if the action could not be processed due to the target entity being not found. Note:
//      * this only occurs for keyed entities, not singleton entities. Note also that this method will
//      * be called in no execution context, which means that one must either perform only thread-safe
//      * operations in the body of this method, or one must dispatch a new action to process the
//      * failure. The default implementation simply logs a warning.
//      *
//      * @param nexus a reference to the nexus for convenient dispatch of a new action.
//      * @param eclass the class of the entity that could not be found.
//      * @param key the key of the entity that could not be found.
//      */
//     public void onDropped (Nexus nexus, Class<?> eclass, Comparable<?> key) {
//         log.warning("Dropping action on unknown entity", "eclass", eclass.getName(), "key", key,
//                     "action", this);
//     }
// }
// 
// Path: core/src/main/java/com/threerings/nexus/distrib/Singleton.java
// public interface Singleton
// {
// }


// Path: server/src/test/java/com/threerings/nexus/server/NexusJavaTest.java
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import com.threerings.nexus.distrib.Action;
import com.threerings.nexus.distrib.Singleton;

//
// Nexus Server - server-side support for Nexus distributed application framework
// http://github.com/threerings/nexus/blob/master/LICENSE

package com.threerings.nexus.server;




public class NexusJavaTest
{
    @Before public void createServer () {
        System.setProperty("nexus.safety_checks", "true");
        _exec = Executors.newFixedThreadPool(3);
        Properties props = new Properties();
        props.setProperty("nexus.node", "test");
        props.setProperty("nexus.hostname", "localhost");
        props.setProperty("nexus.rpc_timeout", "1000");
        _server = new NexusServer(new NexusConfig(props), _exec);
    }

    @After public void shutdownServer () throws Exception {
        _server.shutdown();
        _exec.shutdown();
        if (!_exec.awaitTermination(2, TimeUnit.SECONDS)) {
            fail("Executor failed to terminate after 2 seconds.");
        }
        System.setProperty("nexus.safety_checks", "");
    }

    @Test public void testRuntimeChecksOnAction () {
        final boolean[] printed = new boolean[] { false };

        class EntityA implements Singleton {