@Test
  public void testWithListOfJsonObject() {
    AtomicReference<List<JsonObject>> result = new AtomicReference<>();
    Service service = Service.createProxy(consumerNode.get(), "my.service");
    TestDataObject data = new TestDataObject().setBool(true).setNumber(25).setString("vert.x");
    TestDataObject data2 = new TestDataObject().setBool(true).setNumber(26).setString("vert.x");
    service.methodWithListOfJsonObject(
        Arrays.asList(data.toJson(), data2.toJson()),
        ar -> {
          if (ar.failed()) {
            ar.cause().printStackTrace();
          }
          result.set(ar.result());
        });

    Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> result.get() != null);
    List<JsonObject> out = result.get();

    TestDataObject out0 = new TestDataObject(out.get(0));
    TestDataObject out1 = new TestDataObject(out.get(1));
    assertThat(out0.getNumber()).isEqualTo(25);
    assertThat(out0.isBool()).isTrue();
    assertThat(out0.getString()).isEqualTo("vert.x");
    assertThat(out1.getNumber()).isEqualTo(26);
    assertThat(out1.isBool()).isTrue();
    assertThat(out1.getString()).isEqualTo("vert.x");
  }
Example #2
0
  private void doInserts(final boolean useBulkWriteOperations) {
    getMorphia().setUseBulkWriteOperations(useBulkWriteOperations);
    final DBCollection collection = getDs().getCollection(FacebookUser.class);
    collection.remove(new BasicDBObject());
    final int count = 250000;
    List<FacebookUser> list = new ArrayList<FacebookUser>(count);
    for (int i = 0; i < count; i++) {
      list.add(new FacebookUser(i, "User " + i));
    }

    getAds().insert(list, WriteConcern.UNACKNOWLEDGED);

    Awaitility.await()
        .atMost(30, TimeUnit.SECONDS)
        .until(
            new Callable<Boolean>() {
              @Override
              public Boolean call() throws Exception {
                return collection.count() == count;
              }
            });
    assertEquals(count, collection.count());

    for (FacebookUser user : list) {
      Assert.assertNotNull(user.getId());
    }
  }
  @Test
  public void testVertxEnumAsResult() {
    AtomicReference<SomeVertxEnum> result = new AtomicReference<>();
    Service service = Service.createProxy(consumerNode.get(), "my.service");
    service.methodReturningVertxEnum(
        ar -> {
          result.set(ar.result());
        });

    Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> result.get() == SomeVertxEnum.BAR);
  }
  @Before
  public void setUp() {
    Vertx.clusteredVertx(
        new VertxOptions().setClustered(true).setClusterHost("127.0.0.1"),
        ar -> {
          Vertx vertx = ar.result();
          providerNode.set(vertx);
          vertx.deployVerticle(ServiceProviderVerticle.class.getName());
        });

    Vertx.clusteredVertx(
        new VertxOptions().setClustered(true).setClusterHost("127.0.0.1"),
        ar -> {
          Vertx vertx = ar.result();
          consumerNode.set(vertx);
        });

    Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> providerNode.get() != null);
    Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> consumerNode.get() != null);
  }
  @Test
  public void testEnumAsParameter() {
    AtomicReference<Boolean> result = new AtomicReference<>();
    Service service = Service.createProxy(consumerNode.get(), "my.service");
    service.methodUsingEnum(
        SomeEnum.WIBBLE,
        ar -> {
          result.set(ar.result());
        });

    Awaitility.await()
        .atMost(10, TimeUnit.SECONDS)
        .until(() -> result.get() != null && result.get());
  }
  @Test
  public void testHello() {
    AtomicReference<String> result = new AtomicReference<>();
    Service service = Service.createProxy(consumerNode.get(), "my.service");
    service.hello(
        "vert.x",
        ar -> {
          result.set(ar.result());
        });

    Awaitility.await()
        .atMost(10, TimeUnit.SECONDS)
        .until(() -> "hello vert.x".equalsIgnoreCase(result.get()));
  }
  @Test
  public void testWithJsonObject() {
    AtomicReference<TestDataObject> result = new AtomicReference<>();
    Service service = Service.createProxy(consumerNode.get(), "my.service");
    TestDataObject data = new TestDataObject().setBool(true).setNumber(25).setString("vert.x");
    service.methodWithJsonObject(
        data.toJson(),
        ar -> {
          result.set(new TestDataObject(ar.result()));
        });

    Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> result.get() != null);
    TestDataObject out = result.get();
    assertThat(out.getNumber()).isEqualTo(25);
    assertThat(out.isBool()).isTrue();
    assertThat(out.getString()).isEqualTo("vert.x");
  }
Example #8
0
  @Test(groups = "fast")
  public void testBasicClockOperations() throws Exception {
    final ClockMock clock = new ClockMock();

    final DateTime startingTime = new DateTime(DateTimeZone.UTC);
    // Lame, but required due to the truncation magic
    Awaitility.await()
        .atMost(1001, MILLISECONDS)
        .until(
            new Callable<Boolean>() {
              @Override
              public Boolean call() throws Exception {
                return clock.getUTCNow().isAfter(startingTime);
              }
            });

    clock.setTime(new DateTime(2012, 5, 1, 1, 2, 3, DateTimeZone.UTC));
    Assert.assertEquals(clock.getUTCToday(), new LocalDate(2012, 5, 1));
    final DateTime utcNowAfterSetTime = clock.getUTCNow();
    Assert.assertEquals(utcNowAfterSetTime.getHourOfDay(), 1);
    Assert.assertEquals(utcNowAfterSetTime.getMinuteOfHour(), 2);
    Assert.assertEquals(utcNowAfterSetTime.getSecondOfMinute(), 3);

    clock.addDays(1);
    Assert.assertEquals(clock.getUTCToday(), new LocalDate(2012, 5, 2));

    clock.addMonths(1);
    Assert.assertEquals(clock.getUTCToday(), new LocalDate(2012, 6, 2));

    clock.addYears(1);
    Assert.assertEquals(clock.getUTCToday(), new LocalDate(2013, 6, 2));

    clock.setDay(new LocalDate(2045, 12, 12));
    Assert.assertEquals(clock.getUTCToday(), new LocalDate(2045, 12, 12));

    clock.resetDeltaFromReality();
    Assert.assertTrue(clock.getUTCNow().isAfter(startingTime));
    Assert.assertTrue(clock.getUTCNow().isBefore(startingTime.plusMinutes(1)));
  }
  @Test(groups = "slow")
  public void testFailedPaymentWithPerTenantRetryConfig() throws Exception {
    // Create the tenant
    final String apiKeyTenant1 = "tenantSuperTuned";
    final String apiSecretTenant1 = "2367$$ffr79";
    loginTenant(apiKeyTenant1, apiSecretTenant1);
    final Tenant tenant1 = new Tenant();
    tenant1.setApiKey(apiKeyTenant1);
    tenant1.setApiSecret(apiSecretTenant1);
    killBillClient.createTenant(tenant1, createdBy, reason, comment);

    // Configure our plugin to fail
    mockPaymentProviderPlugin.makeAllInvoicesFailWithError(true);

    // Upload the config
    final ObjectMapper mapper = new ObjectMapper();
    final HashMap<String, String> perTenantProperties = new HashMap<String, String>();
    perTenantProperties.put("org.killbill.payment.retry.days", "1,1,1");
    final String perTenantConfig = mapper.writeValueAsString(perTenantProperties);

    final TenantKey tenantKey =
        killBillClient.postConfigurationPropertiesForTenant(perTenantConfig, basicRequestOptions());

    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();

    final Payments payments = killBillClient.getPaymentsForAccount(accountJson.getAccountId());
    Assert.assertEquals(payments.size(), 1);
    Assert.assertEquals(payments.get(0).getTransactions().size(), 1);

    //
    // Because we have specified a retry interval of one day we should see the new attempt after
    // moving clock 1 day (and not 8 days which is default)
    //

    //
    // Now unregister special per tenant config and we the first retry occurs one day after (and
    // still fails), it now sets a retry date of 8 days
    //
    killBillClient.unregisterConfigurationForTenant(basicRequestOptions());
    // org.killbill.tenant.broadcast.rate has been set to 1s
    crappyWaitForLackOfProperSynchonization(2000);

    clock.addDays(1);

    Awaitility.await()
        .atMost(4, TimeUnit.SECONDS)
        .pollInterval(Duration.ONE_SECOND)
        .until(
            new Callable<Boolean>() {
              @Override
              public Boolean call() throws Exception {

                return killBillClient
                        .getPaymentsForAccount(accountJson.getAccountId())
                        .get(0)
                        .getTransactions()
                        .size()
                    == 2;
              }
            });
    final Payments payments2 = killBillClient.getPaymentsForAccount(accountJson.getAccountId());
    Assert.assertEquals(payments2.size(), 1);
    Assert.assertEquals(payments2.get(0).getTransactions().size(), 2);
    Assert.assertEquals(
        payments2.get(0).getTransactions().get(0).getStatus(),
        TransactionStatus.PAYMENT_FAILURE.name());
    Assert.assertEquals(
        payments2.get(0).getTransactions().get(1).getStatus(),
        TransactionStatus.PAYMENT_FAILURE.name());

    clock.addDays(1);
    crappyWaitForLackOfProperSynchonization(3000);

    // No retry with default config
    final Payments payments3 = killBillClient.getPaymentsForAccount(accountJson.getAccountId());
    Assert.assertEquals(payments3.size(), 1);
    Assert.assertEquals(payments3.get(0).getTransactions().size(), 2);

    mockPaymentProviderPlugin.makeAllInvoicesFailWithError(false);
    clock.addDays(7);

    Awaitility.await()
        .atMost(4, TimeUnit.SECONDS)
        .pollInterval(Duration.ONE_SECOND)
        .until(
            new Callable<Boolean>() {
              @Override
              public Boolean call() throws Exception {
                return killBillClient
                        .getPaymentsForAccount(accountJson.getAccountId())
                        .get(0)
                        .getTransactions()
                        .size()
                    == 3;
              }
            });
    final Payments payments4 = killBillClient.getPaymentsForAccount(accountJson.getAccountId());
    Assert.assertEquals(payments4.size(), 1);
    Assert.assertEquals(payments4.get(0).getTransactions().size(), 3);
    Assert.assertEquals(
        payments4.get(0).getTransactions().get(0).getStatus(),
        TransactionStatus.PAYMENT_FAILURE.name());
    Assert.assertEquals(
        payments4.get(0).getTransactions().get(1).getStatus(),
        TransactionStatus.PAYMENT_FAILURE.name());
    Assert.assertEquals(
        payments4.get(0).getTransactions().get(2).getStatus(), TransactionStatus.SUCCESS.name());
  }
 public static ConditionFactory await() {
   return Awaitility.await().pollInterval(pollInterval, SECONDS).atMost(timeout, SECONDS);
 }