@Test
public void shouldRespondWithDelay() throws Exception {

  String query = "select * from foo where bar = ?";
  RowsMetadata rowsMetadata = new RowsMetadata(Collections.emptyList(), null, new int[0], null);
  Prepared response = new Prepared(new byte[] {1, 7, 9}, null, rowsMetadata, rowsMetadata);
  node.getStubStore()
      .register(
          new StubMapping() {
            @Override
            public boolean matches(Frame frame) {
              Message msg = frame.message;
              if (msg instanceof Prepare) {
                Prepare p = (Prepare) msg;
                return p.cqlQuery.equals(query);
              }
              return false;
            }
            @Override
            public List<Action> getActions(AbstractNode node, Frame frame) {
              List<Action> actions = new ArrayList<>();
              actions.add(new MessageResponseAction(response, 500));
              actions.add(new MessageResponseAction(Options.INSTANCE));
              return actions;
            }
          });
  channel.writeInbound(FrameUtils.wrapRequest(new Prepare(query)));
  // Should be no message immediately due to delay used.
  Frame frame = channel.readOutbound();
  assertThat(frame).isNull();
  // Wait a second for action to be processed
  TimeUnit.SECONDS.sleep(1);
  frame = channel.readOutbound();
  assertThat(frame.message).isSameAs(response);
  // Should be another action that is processed immediately after that is an options message.
  frame = channel.readOutbound();
  assertThat(frame.message).isSameAs(Options.INSTANCE);
}