コード例 #1
0
  public void testWebSocketServer() {

    try {
      // randomly select two clients from the collection.
      for (int i = 0; i <= 1000; i++) {
        NettyTestClient from = clients.get(random.nextInt(clients.size()));
        NettyTestClient to = clients.get(random.nextInt(clients.size()));

        // this needs to be here when testing max size or max connections.
        if (to.isClosed()) {
          continue;
        }

        SocketMessage msg = messages.get(random.nextInt(messages.size()));
        msg.setText("Hola!");
        msg.setFrom(from.getUuid());
        msg.setTo(to.getUuid());
        msg.setDate(new Date());
        String json = JSONUtils.toJson(msg);
        from.send(json);

        Thread.sleep(TestConfig.getInstance().getMessageDelay());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
  public VariableSizeWebSocketTest() {
    try {
      NettyClientFactory factory = new NettyClientFactory();
      clients.addAll(factory.buildClients(TestConfig.getInstance().getMaxPayload()));
      this.buildSocketMessages();

      System.out.println("Scheduling test...");
      scheduled.scheduleAtFixedRate(this, 0, 100, TimeUnit.MILLISECONDS);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #3
0
  public static void main(String[] args) {

    try {
      System.out.println("Test will run for " + RUN_TIME_MIN + " minutes");
      TestConfig cfg = TestConfig.getInstance();
      cfg.overrideProperty("print.on.count", "10");
      cfg.overrideProperty("number.of.clients", "500");
      cfg.overrideProperty("compression.enabled", "false");

      VariableSizeWebSocketTest loader = new VariableSizeWebSocketTest();

      scanner = new Scanner(System.in);
      while (scanner.hasNext()) {
        String cmd = scanner.next();
        if (cmd.equals("stop")) {
          loader.stop();
        }
      }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }