package io.tetrapod.core;

import static org.junit.Assert.assertTrue;
import io.tetrapod.core.rpc.*;
import io.tetrapod.core.utils.Util;
import io.tetrapod.identity.IdentityService;
import io.tetrapod.protocol.core.*;
import io.tetrapod.protocol.service.PauseRequest;

import org.junit.Test;
import org.slf4j.*;

public class SessionTest {

   public static final Logger logger = LoggerFactory.getLogger(SessionTest.class);

   @Test
   public void testClientServer() throws Exception {

      TetrapodService service = new TetrapodService();
      service.startNetwork(null, "e:1");

      Util.sleep(1000);
      IdentityService svc1 = new IdentityService();
      svc1.startNetwork("localhost", null);
      Util.sleep(1000);
      assertTrue(svc1.getEntityId() > 0);

      IdentityService svc2 = new IdentityService();
      svc2.startNetwork("localhost", null);
      Util.sleep(1000);
      assertTrue(svc2.getEntityId() > 0);

      svc1.sendRequest(new PauseRequest(), svc2.getEntityId()).handle(new ResponseHandler() {
         @Override
         public void onResponse(Response res) {
            logger.info("Got my response. YEY! {} {}", res, res.errorCode());
         }
      });

      svc1.addSubscriptionHandler(new TetrapodContract.Services(), new TetrapodContract.Services.API() {

         @Override
         public void messageServiceAdded(ServiceAddedMessage m, MessageContext ctx) {
            logger.info("GOT MESSAGE!!!! {}", m.dump());
         }

         @Override
         public void genericMessage(Message message, MessageContext ctx) {}

         @Override
         public void messageServiceRemoved(ServiceRemovedMessage m, MessageContext ctx) {}

         @Override
         public void messageServiceStats(ServiceStatsMessage m, MessageContext ctx) {}

         @Override
         public void messageServiceUpdated(ServiceUpdatedMessage m, MessageContext ctx) {}

      });

      Util.sleep(2000);

      svc2.sendBroadcastMessage(new ServiceAddedMessage(), svc1.getEntityId(), Core.UNADDRESSED);

      service.broadcastRegistryMessage(new EntityUpdatedMessage(svc2.getEntityId(), 0));

      Util.sleep(2000);

      service.stop();
      Util.sleep(1000);
   }
}

@@ -1949,17 +1949,8 @@
 send
-Broadcast
 Mess

fix test