Package org.bson

Examples of org.bson.BSONObject


    Map<String, Long> args = new HashMap<>();
    args.put("A", 10L);
    args.put("Count", 20L);
    args.put("ErrorAt", -1L);
    args.put("BadTypeAt", 4L);
    BSONObject mArgs = new BasicBSONObject();
    mArgs.putAll(args);
    client.streamCall("Arith.Thrive", mArgs);
    Response response;
    long index = 0;
    while (index < args.get("BadTypeAt") && (response = client.streamNext()) != null) {
      BSONObject result = (BSONObject) response.getReply();
      Assert.assertEquals(args.get("A"), result.get("C"));
      Assert.assertEquals(index, result.get("Index"));
      index++;
    }

    Assert.assertEquals(args.get("BadTypeAt").longValue(), index);
    try {
View Full Code Here


    Map<String, Long> args = new HashMap<>();
    args.put("A", 10L);
    args.put("Count", 3L);
    args.put("ErrorAt", -1L);
    args.put("BadTypeAt", -1L);
    BSONObject mArgs = new BasicBSONObject();
    mArgs.putAll(args);
    client.streamCall("Arith.Thrive", mArgs);
    try {
      client.call("Arith.Multiply", mArgs);
      Assert.fail("failed to raise exception");
    } catch (GoRpcException e) {
View Full Code Here

    Map<String, Long> args = new HashMap<>();
    args.put("A", 10L);
    args.put("Count", 3L);
    args.put("ErrorAt", -1L);
    args.put("BadTypeAt", -1L);
    BSONObject mArgs = new BasicBSONObject();
    mArgs.putAll(args);
    client.streamCall("Arith.Thrive", mArgs);
    while (client.streamNext() != null) {
    }

    try {
View Full Code Here

  public void tearDown() throws IOException {}

  @Test
  public void testDivide() throws GoRpcException, IOException, ApplicationException {
    Client client = Client.dialHttp(Util.HOST, Util.PORT, Util.PATH, new BsonClientCodecFactory());
    BSONObject mArgs = new BasicBSONObject();
    mArgs.put("A", 10L);
    mArgs.put("B", 3L);
    Response response = client.call("Arith.Divide", mArgs);
    BSONObject result = (BSONObject) response.getReply();
    Assert.assertEquals(3L, result.get("Quo"));
    Assert.assertEquals(1L, result.get("Rem"));
    client.close();
  }
View Full Code Here

  }

  @Test
  public void testDivideError() throws GoRpcException, IOException, ApplicationException {
    Client client = Client.dialHttp(Util.HOST, Util.PORT, Util.PATH, new BsonClientCodecFactory());
    BSONObject mArgs = new BasicBSONObject();
    mArgs.put("A", 10L);
    mArgs.put("B", 0L);
    try {
      client.call("Arith.Divide", mArgs);
      Assert.fail("did not raise application error");
    } catch (ApplicationException e) {
      Assert.assertEquals("divide by zero", e.getMessage());
View Full Code Here

    timeoutCheck(client, clientTimeoutMs * 2, true);
    client.close();
  }

  private void timeoutCheck(Client client, int timeoutMs, boolean shouldTimeout) throws Exception {
    BSONObject mArgs = new BasicBSONObject();
    mArgs.put("Duration", timeoutMs);

    if (shouldTimeout) {
      try {
        client.call("Arith.Sleep", mArgs);
        Assert.fail("did not raise timeout error");
View Full Code Here

   */
  @Test
  public void testUnsignedLongs() throws Exception {
    UnsignedLong a = UnsignedLong.valueOf("9767889778372766922");
    Client client = Client.dialHttp(Util.HOST, Util.PORT, Util.PATH, new BsonClientCodecFactory());
    BSONObject mArgs = new BasicBSONObject();
    mArgs.put("Num", a);
    Response response = client.call("Arith.Increment", mArgs);
    Assert.assertEquals(a.add(UnsignedLong.ONE), (UnsignedLong) response.getReply());
    client.close();
  }
View Full Code Here

  }

  @Test
  public void testValidCase() throws IOException, GoRpcException, ApplicationException {
    Client client = Client.dialHttp(Util.HOST, Util.PORT, Util.PATH, new BsonClientCodecFactory());
    BSONObject mArgs = new BasicBSONObject();
    mArgs.put("A", 5L);
    mArgs.put("B", 7L);
    Response response = client.call("Arith.Multiply", mArgs);
    Assert.assertNull(response.getError());
    Assert.assertEquals(35L, response.getReply());
    client.close();
  }
View Full Code Here

  }

  @Test
  public void testMissingMethodArgs() throws IOException, GoRpcException, ApplicationException {
    Client client = Client.dialHttp(Util.HOST, Util.PORT, Util.PATH, new BsonClientCodecFactory());
    BSONObject mArgs = new BasicBSONObject();
    mArgs.put("A", 5L);
    // incomplete args defaults to zero values
    Response response = client.call("Arith.Multiply", mArgs);
    Assert.assertEquals(0L, response.getReply());
    Assert.assertNull(response.getError());
    client.close();
View Full Code Here

  @Test
  public void testValidMultipleCalls() throws IOException, GoRpcException, ApplicationException {
    Client client = Client.dialHttp(Util.HOST, Util.PORT, Util.PATH, new BsonClientCodecFactory());

    BSONObject mArgs = new BasicBSONObject();
    mArgs.put("A", 5L);
    mArgs.put("B", 7L);
    Response response = client.call("Arith.Multiply", mArgs);
    Assert.assertEquals(35L, response.getReply());

    mArgs = new BasicBSONObject();
    mArgs.put("A", 2L);
    mArgs.put("B", 3L);
    response = client.call("Arith.Multiply", mArgs);
    Assert.assertEquals(6L, response.getReply());

    client.close();
  }
View Full Code Here

TOP

Related Classes of org.bson.BSONObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.