com.jayway.awaitility.Awaitility Java Examples

The following examples show how to use com.jayway.awaitility.Awaitility. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EventBusBridgeTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatEventBusMessagesContainingNoBodyAreTransferredToStomp() {
  AtomicReference<Frame> reference = new AtomicReference<>();

  clients.add(StompClient.create(vertx).connect(ar -> {
        final StompClientConnection connection = ar.result();
        connection.subscribe("/bus", reference::set,
            f -> {
              vertx.eventBus().publish("/bus", null,
                  new DeliveryOptions().addHeader("foo", "bar"));
            }
        );
      }
  ));

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> reference.get() != null);

  assertThat(reference.get().getHeaders().get("foo")).isEqualTo("bar");
  assertThat(reference.get().getHeaders().get("destination")).isEqualTo("/bus");
  byte[] body = reference.get().getBody().getBytes();
  assertThat(body).hasSize(0);
}
 
Example #2
Source File: JobActivityPublisherTest.java    From titus-control-plane with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublishJobUpdateEvent() throws Exception {
    when(v3JobOperations.observeJobs()).thenReturn(Observable.from(jobUpdateEvents));

    // Start consumption of the event stream until it fully consumes it
    publisherService.activate();

    Awaitility.await().timeout(5, TimeUnit.SECONDS).until(() -> !publisherService.isActive());

    // Verify that all of the emitted events were consumed and published
    StepVerifier.create(publisherStore.getSize())
            .expectNext(numBatchJobs)
            .verifyComplete();

    // Verify that published records are correct
    StepVerifier.create(publisherStore.getRecords())
            .thenConsumeWhile(jobActivityPublisherRecord ->
                    jobActivityPublisherRecord.getRecordType() == JobActivityPublisherRecord.RecordType.JOB)
            .verifyComplete();
}
 
Example #3
Source File: StandaloneClientTest.java    From Ratel with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() {
    ConfigurableApplicationContext ctx = SpringApplication.run(new Object[] {TestServiceConfiguration.class,
            ServiceDiscoveryConfig.class, DiscoveryServerMain.class}, new String[] {"--server.port=17070",
            "--" + JBOSS_BIND_ADDRESS + "=localhost", "--" + JBOSS_BIND_PORT + "=17070",
            "--spring.jmx.enabled=false", "--" + SERVICE_DISCOVERY_ADDRESS + "=http://localhost:17070"
                    + "/server/discovery"});

    final InMemoryDiscoveryServer server = ctx.getBean(InMemoryDiscoveryServer.class);
    Awaitility.await().atMost(40, TimeUnit.SECONDS).until(new Runnable() {

        @Override
        public void run() {
            assertThat(server.fetchAllServices()).hasSize(2);
        }
    });

    this.startedApp = ctx;
}
 
Example #4
Source File: ESTasks.java    From elasticsearch with Apache License 2.0 6 votes vote down vote up
public void waitForGreen(Integer numNodes) {
    LOGGER.debug("Wating for green and " + numNodes + " nodes.");
    Awaitility.await().atMost(5, TimeUnit.MINUTES).pollInterval(1, TimeUnit.SECONDS).until(() -> { // This can take some time, somtimes.
        try {
            List<String> esAddresses = getEsHttpAddressList();
            // This may throw a JSONException if we call before the JSON has been generated. Hence, catch exception.
            final JSONObject body = Unirest.get("http://" + esAddresses.get(0) + "/_cluster/health").asJson().getBody().getObject();
            final boolean numberOfNodes = body.getInt("number_of_nodes") == numNodes;
            final boolean green = body.getString("status").equals("green");
            final boolean initializingShards = body.getInt("initializing_shards") == 0;
            final boolean unassignedShards = body.getInt("unassigned_shards") == 0;
            LOGGER.debug(green + " and " + numberOfNodes + " and " + initializingShards + " and " + unassignedShards + ": " + body);
            return green && numberOfNodes && initializingShards && unassignedShards;
        } catch (Exception e) {
            LOGGER.debug(e);
            return false;
        }
    });
}
 
Example #5
Source File: FrameworkRoleSystemTest.java    From elasticsearch with Apache License 2.0 6 votes vote down vote up
private void testMiniMesosReportsFrameworkRole(String role) throws UnirestException, JsonParseException, JsonMappingException {
    LOGGER.info("Starting Elasticsearch scheduler with framework role: " + role);
    ElasticsearchSchedulerContainer scheduler = new ElasticsearchSchedulerContainer(getDockerClient(),
            CLUSTER.getZooKeeper().getIpAddress(),
            role,
            org.apache.mesos.elasticsearch.scheduler.Configuration.DEFAULT_HOST_DATA_DIR);
    CLUSTER.addAndStartProcess(scheduler, TEST_CONFIG.getClusterTimeout());
    LOGGER.info("Started Elasticsearch scheduler on " + scheduler.getIpAddress() + ":" + getTestConfig().getSchedulerGuiPort());

    ESTasks esTasks = new ESTasks(TEST_CONFIG, scheduler.getIpAddress());
    new TasksResponse(esTasks, TEST_CONFIG.getElasticsearchNodesCount());
    new ElasticsearchNodesResponse(esTasks, TEST_CONFIG.getElasticsearchNodesCount());

    Awaitility.await().atMost(30, TimeUnit.SECONDS).pollInterval(5, TimeUnit.SECONDS).until(() -> getStateInfo(CLUSTER).getFramework("elasticsearch") != null);
    Assert.assertEquals(role, getStateInfo(CLUSTER).getFramework("elasticsearch").getRole());
}
 
Example #6
Source File: ESTasks.java    From elasticsearch with Apache License 2.0 6 votes vote down vote up
public void waitForCorrectDocumentCount(Integer docCount) throws UnirestException {
    List<String> esAddresses = getEsHttpAddressList();
    Awaitility.await().atMost(1, TimeUnit.MINUTES).pollDelay(2, TimeUnit.SECONDS).until(() -> {
        for (String httpAddress : esAddresses) {
            try {
                Integer count = getDocumentCount(httpAddress);
                if (docCount != 0 && (count == 0 || count % docCount != 0)) { // This allows for repeated testing. Only run if docCount != 0.
                    return false;
                }
            } catch (Exception e) {
                LOGGER.error("Unirest exception:" + e.getMessage());
                return false;
            }
        }
        return true;
    });
}
 
Example #7
Source File: ESTasks.java    From elasticsearch with Apache License 2.0 6 votes vote down vote up
public List<JSONObject> getTasks() {
    List<JSONObject> tasks = new ArrayList<>();
    LOGGER.debug("Fetching tasks on " + tasksEndPoint);
    final AtomicReference<HttpResponse<JsonNode>> response = new AtomicReference<>();
    Awaitility.await().atMost(30, TimeUnit.SECONDS).pollInterval(1, TimeUnit.SECONDS).until(() -> { // This can take some time, somtimes.
        try {
            response.set(Unirest.get(tasksEndPoint).asJson());
            return true;
        } catch (UnirestException e) {
            LOGGER.debug(e);
            return false;
        }
    });
    for (int i = 0; i < response.get().getBody().getArray().length(); i++) {
        JSONObject jsonObject = response.get().getBody().getArray().getJSONObject(i);
        tasks.add(jsonObject);
    }
    return tasks;
}
 
Example #8
Source File: DifferentESVersionSystemTest.java    From elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldStartDockerImage() {
    IpTables.apply(dockerClient, cluster, TEST_CONFIG); // Only forward docker traffic

    final DockerESVersionScheduler scheduler = new DockerESVersionScheduler(dockerClient, cluster.getZooKeeper().getIpAddress(), cluster, ES_IMAGE);
    cluster.addAndStartProcess(scheduler, TEST_CONFIG.getClusterTimeout());
    LOG.info("Started Elasticsearch scheduler on " + scheduler.getIpAddress() + ":" + TEST_CONFIG.getSchedulerGuiPort());

    ESTasks esTasks = new ESTasks(TEST_CONFIG, scheduler.getIpAddress());
    new TasksResponse(esTasks, TEST_CONFIG.getElasticsearchNodesCount());

    ElasticsearchNodesResponse nodesResponse = new ElasticsearchNodesResponse(esTasks, TEST_CONFIG.getElasticsearchNodesCount());
    assertTrue("Elasticsearch nodes did not discover each other within 5 minutes", nodesResponse.isDiscoverySuccessful());

    final AtomicReference<String> versionNumber = new AtomicReference<>("");
    Awaitility.await().pollInterval(1L, TimeUnit.SECONDS).atMost(TEST_CONFIG.getClusterTimeout(), TimeUnit.SECONDS).until(() -> {
        try {
            versionNumber.set(Unirest.get("http://" + esTasks.getEsHttpAddressList().get(0)).asJson().getBody().getObject().getJSONObject("version").getString("number"));
            return true;
        } catch (UnirestException e) {
            return false;
        }
    });
    assertEquals("ES version is not the same as requested: " + ES_VERSION + " != " + versionNumber.get(), ES_VERSION, versionNumber.get());
}
 
Example #9
Source File: DifferentESVersionSystemTest.java    From elasticsearch with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldStartJar() {
    // Don't forward traffic. Jars are actually running on the slaves
    final JarESVersionScheduler scheduler = new JarESVersionScheduler(dockerClient, cluster.getZooKeeper().getIpAddress(), cluster, ES_BINARY);
    cluster.addAndStartProcess(scheduler, TEST_CONFIG.getClusterTimeout());
    LOG.info("Started Elasticsearch scheduler on " + scheduler.getIpAddress() + ":" + TEST_CONFIG.getSchedulerGuiPort());

    ESTasks esTasks = new ESTasks(TEST_CONFIG, scheduler.getIpAddress());
    new TasksResponse(esTasks, TEST_CONFIG.getElasticsearchNodesCount());

    ElasticsearchNodesResponse nodesResponse = new ElasticsearchNodesResponse(esTasks, TEST_CONFIG.getElasticsearchNodesCount());
    assertTrue("Elasticsearch nodes did not discover each other within 5 minutes", nodesResponse.isDiscoverySuccessful());

    final AtomicReference<String> versionNumber = new AtomicReference<>("");
    Awaitility.await().pollInterval(1L, TimeUnit.SECONDS).atMost(TEST_CONFIG.getClusterTimeout(), TimeUnit.SECONDS).until(() -> {
        try {
            versionNumber.set(Unirest.get("http://" + esTasks.getEsHttpAddressList().get(0)).asJson().getBody().getObject().getJSONObject("version").getString("number"));
            return true;
        } catch (UnirestException e) {
            return false;
        }
    });
    assertEquals("ES version is not the same as requested: " + ES_VERSION + " != " + versionNumber.get(), ES_VERSION, versionNumber.get());
}
 
Example #10
Source File: MultiInstanceTransactionTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatTransactionAreNotShared(TestContext context) {
  vertx.deployVerticle("io.vertx.ext.stomp.verticles.StompServerVerticle", new DeploymentOptions().setInstances(3),
      ar -> {
        if (ar.failed()) {
          context.fail(ar.cause());
        } else {
          deploymentId = ar.result();
          // Deploy the clients.
          vertx.deployVerticle("io.vertx.ext.stomp.verticles.ReceiverStompClient", ar2 -> {
            if (ar.failed()) {
              context.fail(ar.cause());
            } else {
              vertx.deployVerticle("io.vertx.ext.stomp.verticles.TxSenderStompClient", ar3 -> {
                System.out.println("Test started");
              });
            }
          });
        }
      });

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> ReceiverStompClient.FRAMES.size() == 5);
}
 
Example #11
Source File: MultiInstanceSubscriptionTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatTopicSubscriptionsAreShared(TestContext context) {
  vertx.deployVerticle("io.vertx.ext.stomp.verticles.StompServerVerticle", new DeploymentOptions().setInstances(3),
      ar -> {
        if (ar.failed()) {
          context.fail(ar.cause());
        } else {
          deploymentId = ar.result();
          // Deploy the clients.
          vertx.deployVerticle("io.vertx.ext.stomp.verticles.ReceiverStompClient",
              new DeploymentOptions().setInstances(3), ar2 -> {
            if (ar.failed()) {
              context.fail(ar.cause());
            } else {
              vertx.deployVerticle("io.vertx.ext.stomp.verticles.TxSenderStompClient", new DeploymentOptions()
                  .setInstances(2));
            }
          });
        }
      });

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> ReceiverStompClient.FRAMES.size() == 5 * 3 * 2);
}
 
Example #12
Source File: MultiInstanceSubscriptionTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatQueueSubscriptionsAreShared(TestContext context) {
  vertx.deployVerticle("io.vertx.ext.stomp.verticles.StompServerVerticle", new DeploymentOptions()
          .setConfig(new JsonObject().put("useQueue", true))
          .setInstances(3),
      ar -> {
        if (ar.failed()) {
          context.fail(ar.cause());
        } else {
          deploymentId = ar.result();
          // Deploy the clients.
          vertx.deployVerticle("io.vertx.ext.stomp.verticles.ReceiverStompClient",
              new DeploymentOptions().setInstances(3), ar2 -> {
                if (ar.failed()) {
                  context.fail(ar.cause());
                } else {
                  vertx.deployVerticle("io.vertx.ext.stomp.verticles.TxSenderStompClient", new DeploymentOptions()
                      .setInstances(2));
                }
              });
        }
      });

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> ReceiverStompClient.FRAMES.size() == 5 * 2);
}
 
Example #13
Source File: EventBusBridgeTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatStompMessagesAreTransferredToTheEventBus() {
  AtomicReference<Message> reference = new AtomicReference<>();
  consumers.add(vertx.eventBus().consumer("/bus", reference::set));

  clients.add(StompClient.create(vertx).connect(ar -> {
    final StompClientConnection connection = ar.result();
    connection.send("/bus", Headers.create("foo", "bar"), Buffer.buffer("Hello from STOMP"));
  }));

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> reference.get() != null);
  assertThat(reference.get().headers().get("foo")).isEqualTo("bar");
  assertThat(reference.get().headers().get("destination")).isEqualTo("/bus");
  assertThat(reference.get().headers().get("content-length")).isEqualTo("16");
  assertThat(reference.get().address()).isEqualTo("/bus");
  assertThat(reference.get().replyAddress()).isNullOrEmpty();
  assertThat(reference.get().body().toString()).isEqualTo("Hello from STOMP");
}
 
Example #14
Source File: EventBusBridgeTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatEventBusMessagesAreTransferredToStomp() {
  AtomicReference<Frame> reference = new AtomicReference<>();

  clients.add(StompClient.create(vertx).connect(ar -> {
        final StompClientConnection connection = ar.result();
        connection.subscribe("/bus", reference::set,
            f -> {
              vertx.eventBus().publish("/bus", "Hello from Vert.x", new DeliveryOptions().addHeader("foo", "bar"));
            }
        );
      }
  ));

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> reference.get() != null);

  assertThat(reference.get().getHeaders().get("foo")).isEqualTo("bar");
  assertThat(reference.get().getHeaders().get("destination")).isEqualTo("/bus");
  assertThat(reference.get().getHeaders().get("content-length")).isEqualTo("17");
  assertThat(reference.get().getBodyAsString()).isEqualTo("Hello from Vert.x");
}
 
Example #15
Source File: EventBusBridgeTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatEventBusMessagesContainingBufferAreTransferredToStomp() {
  AtomicReference<Frame> reference = new AtomicReference<>();

  byte[] bytes = new byte[]{0, 1, 2, 3, 4, 5, 6};
  clients.add(StompClient.create(vertx).connect(ar -> {
        final StompClientConnection connection = ar.result();
        connection.subscribe("/bus", reference::set,
            f -> {
              vertx.eventBus().publish("/bus", Buffer.buffer(bytes),
                  new DeliveryOptions().addHeader("foo", "bar"));
            }
        );
      }
  ));

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> reference.get() != null);

  assertThat(reference.get().getHeaders().get("foo")).isEqualTo("bar");
  assertThat(reference.get().getHeaders().get("destination")).isEqualTo("/bus");
  byte[] body = reference.get().getBody().getBytes();
  assertThat(body).containsExactly(bytes);
}
 
Example #16
Source File: EventBusBridgeTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatEventBusConsumerCanReplyToStompMessages() {
  server.stompHandler().bridge(new BridgeOptions()
          .addOutboundPermitted(new PermittedOptions().setAddress("/replyTo"))
          .addInboundPermitted(new PermittedOptions().setAddress("/request"))
          .setPointToPoint(true)
  );

  AtomicReference<Frame> response = new AtomicReference<>();

  consumers.add(vertx.eventBus().consumer("/request", msg -> {
    msg.reply("pong");
  }));

  clients.add(StompClient.create(vertx).connect(ar -> {
    final StompClientConnection connection = ar.result();
    connection.subscribe("/replyTo", response::set, r1 -> {
      connection.send("/request", Headers.create("reply-address", "/replyTo"), Buffer.buffer("ping"));
    });
  }));

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> response.get() != null);
}
 
Example #17
Source File: EventBusBridgeTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatEventBusMessagesAreTransferredToSeveralStompClients() {
  List<Frame> frames = new CopyOnWriteArrayList<>();

  clients.add(StompClient.create(vertx).connect(ar -> {
    final StompClientConnection connection = ar.result();
    connection.subscribe("/bus", frames::add,
        f -> {
          clients.add(StompClient.create(vertx).connect(ar2 -> {
            final StompClientConnection connection2 = ar2.result();
            connection2.subscribe("/bus", frames::add, receipt -> {
              vertx.eventBus().publish("/bus", "Hello from Vert.x", new DeliveryOptions().addHeader("foo", "bar"));
            });
          }));
        });
  }));

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> frames.size() == 2);
}
 
Example #18
Source File: EventBusBridgeTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatStompClientCanUnsubscribe() throws InterruptedException {
  List<Frame> frames = new ArrayList<>();

  clients.add(StompClient.create(vertx).connect(ar -> {
        final StompClientConnection connection = ar.result();
        connection.subscribe("/bus", frame -> {
              frames.add(frame);
              connection.unsubscribe("/bus");
            },
            f -> {
              vertx.eventBus().publish("/bus", "Hello from Vert.x", new DeliveryOptions().addHeader("foo", "bar"));
            }
        );
      }
  ));

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> frames.size() == 1);

  // Send another message
  vertx.eventBus().publish("/bus", "Hello from Vert.x", new DeliveryOptions().addHeader("foo", "bar"));

  Thread.sleep(500);
  assertThat(frames).hasSize(1);
}
 
Example #19
Source File: EventBusBridgeTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatStompClientCanCloseTheConnection() throws InterruptedException {
  List<Frame> frames = new ArrayList<>();

  clients.add(StompClient.create(vertx).connect(ar -> {
        final StompClientConnection connection = ar.result();
        connection.subscribe("/bus", frame -> {
              frames.add(frame);
              connection.close();
            },
            f -> {
              vertx.eventBus().publish("/bus", "Hello from Vert.x", new DeliveryOptions().addHeader("foo", "bar"));
            }
        );
      }
  ));

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> frames.size() == 1);

  // Send another message
  vertx.eventBus().publish("/bus", "Hello from Vert.x", new DeliveryOptions().addHeader("foo", "bar"));

  Thread.sleep(500);
  assertThat(frames).hasSize(1);
}
 
Example #20
Source File: EventBusBridgeTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testThatStompClientCanDisconnect() throws InterruptedException {
  List<Frame> frames = new ArrayList<>();

  clients.add(StompClient.create(vertx).connect(ar -> {
        final StompClientConnection connection = ar.result();
        connection.subscribe("/bus", frame -> {
              frames.add(frame);
              connection.disconnect();
            },
            f -> {
              vertx.eventBus().publish("/bus", "Hello from Vert.x", new DeliveryOptions().addHeader("foo", "bar"));
            }
        );
      }
  ));

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> frames.size() == 1);

  // Send another message
  vertx.eventBus().publish("/bus", "Hello from Vert.x", new DeliveryOptions().addHeader("foo", "bar"));

  Thread.sleep(500);
  assertThat(frames).hasSize(1);
}
 
Example #21
Source File: SubscriptionsUsingTopicTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubscriptionsUsingTheSameDefaultId() {
  AtomicBoolean failureDetected = new AtomicBoolean();
  clients.add(StompClient.create(vertx).connect(ar -> {
    final StompClientConnection connection = ar.result();
    connection.subscribe("/topic", frame -> {
    });
    try {
      connection.subscribe("/topic", frame -> {
      });
    } catch (IllegalArgumentException e) {
      failureDetected.set(true);
    }
  }));
  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(failureDetected::get);
}
 
Example #22
Source File: SubscriptionsUsingTopicTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubscriptionsUsingTheSameCustomId() {
  AtomicBoolean failureDetected = new AtomicBoolean();
  clients.add(StompClient.create(vertx).connect(ar -> {
    final StompClientConnection connection = ar.result();
    connection.subscribe("/topic", Headers.create("id", "0"), frame -> {
    });
    try {
      connection.subscribe("/queue2", Headers.create("id", "0"), frame -> {
      });
    } catch (IllegalArgumentException e) {
      failureDetected.set(true);
    }
  }));
  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(failureDetected::get);
}
 
Example #23
Source File: ServerConnectionTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidUnsubscribe(TestContext context) {
  List<Buffer> frames = new ArrayList<>();
  AtomicReference<NetSocket> reference = new AtomicReference<>();

  client = vertx.createNetClient().connect(server.actualPort(), "0.0.0.0", result -> {
    if (result.failed()) {
      context.fail("Connection failed");
      return;
    }
    NetSocket socket = result.result();
    reference.set(socket);
    socket.handler(buffer -> {
      if (buffer.toString().contains("CONNECTED")) {
        socket.write("UNSUBSCRIBE\n" + "id:0\n\n" + FrameParser.NULL);
      } else {
        frames.add(buffer);
      }
    });
    socket.write("CONNECT\n" + "accept-version:1.2\n" + "\n" + FrameParser.NULL);
  });

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> frames.size() >= 1);

  assertThat(frames.get(0).toString()).startsWith("ERROR");
}
 
Example #24
Source File: ServerConnectionTest.java    From vertx-stomp with Apache License 2.0 6 votes vote down vote up
@Test
public void testMalformedFrame(TestContext context) {
  List<Buffer> frames = new ArrayList<>();

  client = vertx.createNetClient().connect(server.actualPort(), "0.0.0.0", result -> {
    if (result.failed()) {
      context.fail("Connection failed");
      return;
    }
    NetSocket socket = result.result();
    socket.handler(frames::add);
    socket.write("CONNECT\n" + "accept-version:1.2\n" + "\n" + "illegal body" + FrameParser.NULL);
  });

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> frames.size() >= 1);

  assertThat(frames.get(0).toString()).startsWith("ERROR");
}
 
Example #25
Source File: DefaultDependencyWatcherSpringTests.java    From spring-cloud-zookeeper with Apache License 2.0 6 votes vote down vote up
@Ignore // FIXME 2.0.0
@Test
public void should_verify_that_dependency_watcher_listener_is_successfully_registered_and_operational()
		throws Exception {
	// when:
	this.registry.deregister(this.zookeeperRegistration);

	// then:
	Awaitility.await().until(new Callable<Boolean>() {
		@Override
		public Boolean call() throws Exception {
			then(DefaultDependencyWatcherSpringTests.this.dependencyWatcherListener.dependencyState)
					.isEqualTo(DependencyState.DISCONNECTED);
			return true;
		}
	});
}
 
Example #26
Source File: DnsSrvResolversIT.java    From dns-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testCorrectSequenceOfNotifications() {
  ChangeNotifier<LookupResult> notifier = ChangeNotifiers.aggregate(
      DnsSrvWatchers.newBuilder(resolver)
          .polling(100, TimeUnit.MILLISECONDS)
          .build().watch("_spotify-client._tcp.spotify.com"));

  final List<String> changes = Collections.synchronizedList(new ArrayList<>());

  notifier.setListener(changeNotification -> {
    Set<LookupResult> current = changeNotification.current();
    if (!ChangeNotifiers.isInitialEmptyData(current)) {
      changes.add(current.isEmpty() ? "empty" : "data");
    }
  }, true);
  assertThat(changes, Matchers.empty());
  Awaitility.await().atMost(2, TimeUnit.SECONDS).until(() -> changes.size() >= 1);
  assertThat(changes, containsInAnyOrder("data"));
}
 
Example #27
Source File: ClusteredTest.java    From vertx-service-proxy with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithListOfDataObject() {
  AtomicReference<List<TestDataObject>> 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.methodWithListOfDataObject(Arrays.asList(data, data2), ar -> {
    if (ar.failed()) {
      ar.cause().printStackTrace();
    }
    result.set(ar.result());
  });

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> result.get() != null);
  List<TestDataObject> out = result.get();
  assertThat(out.get(0).getNumber()).isEqualTo(25);
  assertThat(out.get(0).isBool()).isTrue();
  assertThat(out.get(0).getString()).isEqualTo("vert.x");
  assertThat(out.get(1).getNumber()).isEqualTo(26);
  assertThat(out.get(1).isBool()).isTrue();
  assertThat(out.get(1).getString()).isEqualTo("vert.x");
}
 
Example #28
Source File: ClusteredTest.java    From vertx-service-proxy with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithListOfStringDataObject() {
  AtomicReference<List<StringDataObject>> result = new AtomicReference<>();
  Service service = Service.createProxy(consumerNode.get(), "my.service");
  StringDataObject data = new StringDataObject().setValue("vert.x-1");
  StringDataObject data2 = new StringDataObject().setValue("vert.x-2");
  service.methodWithListOfStringDataObject(Arrays.asList(data, data2), ar -> {
    if (ar.failed()) {
      ar.cause().printStackTrace();
    }
    result.set(ar.result());
  });

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> result.get() != null);
  List<StringDataObject> out = result.get();
  assertThat(out.get(0).getValue()).isEqualTo("vert.x-1");
  assertThat(out.get(1).getValue()).isEqualTo("vert.x-2");
}
 
Example #29
Source File: ClusteredTest.java    From vertx-service-proxy with Apache License 2.0 6 votes vote down vote up
@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 #30
Source File: ClusteredTest.java    From vertx-service-proxy with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithJsonArray() {
  AtomicReference<JsonArray> result = new AtomicReference<>();
  Service service = Service.createProxy(consumerNode.get(), "my.service");
  TestDataObject data = new TestDataObject().setBool(true).setNumber(25).setString("vert.x");
  JsonArray array = new JsonArray();
  array.add("vert.x").add(data.toJson());

  service.methodWithJsonArray(array, ar -> {
    result.set(ar.result());
  });

  Awaitility.await().atMost(10, TimeUnit.SECONDS).until(() -> result.get() != null);
  TestDataObject out = new TestDataObject(result.get().getJsonObject(1));
  assertThat(array.getString(0)).isEqualToIgnoringCase("vert.x");
  assertThat(out.getNumber()).isEqualTo(25);
  assertThat(out.isBool()).isTrue();
  assertThat(out.getString()).isEqualTo("vert.x");
}