Ejemplo n.º 1
0
  @Test
  public void testToString() throws Exception {
    String str = TestUtils.randomUnicodeString(100);
    Buffer buff = new Buffer(str);
    assertEquals(str, buff.toString());

    // TODO toString with encoding
  }
Ejemplo n.º 2
0
  @Test
  public void testAppendString1() throws Exception {

    String str = TestUtils.randomUnicodeString(100);
    byte[] sb = str.getBytes("UTF-8");

    Buffer b = new Buffer();
    b.appendString(str);
    assertEquals(b.length(), sb.length);
    assertTrue(str.equals(b.toString("UTF-8")));
  }
Ejemplo n.º 3
0
  @Test
  public void testCreateBuffers() throws Exception {
    Buffer buff = new Buffer(1000);
    assertEquals(0, buff.length());

    String str = TestUtils.randomUnicodeString(100);
    buff = new Buffer(str);
    assertEquals(buff.length(), str.getBytes("UTF-8").length);
    assertEquals(str, buff.toString());

    // TODO create with string with encoding

    byte[] bytes = TestUtils.generateRandomByteArray(100);
    buff = new Buffer(bytes);
    assertEquals(buff.length(), bytes.length);
    assertTrue(TestUtils.buffersEqual(new Buffer(bytes), new Buffer(buff.getBytes())));
  }
Ejemplo n.º 4
0
  private void parseConfigAndStart(final Buffer buffer) {
    final JsonObject config = new JsonObject(buffer.toString());

    container.deployModule(
        METRICS_MODULE,
        config.getObject("metrics"),
        ar -> {
          if (ar.succeeded()) {
            container
                .logger()
                .fatal("Deployed: " + METRICS_MODULE + " with id: " + ar.result(), ar.cause());

            start(config);
          } else {
            container.logger().fatal("Failed to deploy: " + METRICS_MODULE, ar.cause());
          }
        });
  }
Ejemplo n.º 5
0
  private void handleSocketData(
      SockJSSocket sock, Buffer data, Map<String, Handler<Message>> handlers) {
    JsonObject msg = new JsonObject(data.toString());

    String type = getMandatoryString(msg, "type");
    String address = getMandatoryString(msg, "address");
    switch (type) {
      case "send":
        internalHandleSendOrPub(sock, true, msg, address);
        break;
      case "publish":
        internalHandleSendOrPub(sock, false, msg, address);
        break;
      case "register":
        internalHandleRegister(sock, address, handlers);
        break;
      case "unregister":
        internalHandleUnregister(sock, address, handlers);
        break;
      default:
        throw new IllegalStateException("Invalid type: " + type);
    }
  }
 public void handle(Buffer data) {
   ws.writeTextFrame(data.toString());
 }