Ejemplo n.º 1
0
 @Test(expected = NullPointerException.class)
 public void portIsRequired() throws ValidationException {
   try {
     GraphiteWriter.builder().setHost("localhost").build();
   } catch (NullPointerException npe) {
     assertThat(npe).hasMessage("Port cannot be null.");
     throw npe;
   }
 }
Ejemplo n.º 2
0
  private static GraphiteWriter getGraphiteWriter(OutputStream out, List<String> typeNames)
      throws Exception {
    GenericKeyedObjectPool<InetSocketAddress, Socket> pool = mock(GenericKeyedObjectPool.class);
    Socket socket = mock(Socket.class);
    when(pool.borrowObject(Matchers.any(InetSocketAddress.class))).thenReturn(socket);

    when(socket.getOutputStream()).thenReturn(out);

    GraphiteWriter writer =
        GraphiteWriter.builder().setHost("localhost").setPort(2003).addTypeNames(typeNames).build();
    writer.setPool(pool);

    return writer;
  }
Ejemplo n.º 3
0
  @Test
  public void socketInvalidatedWhenError() throws Exception {
    GenericKeyedObjectPool<InetSocketAddress, Socket> pool = mock(GenericKeyedObjectPool.class);
    Socket socket = mock(Socket.class);
    when(pool.borrowObject(Matchers.any(InetSocketAddress.class))).thenReturn(socket);
    UnflushableByteArrayOutputStream out = new UnflushableByteArrayOutputStream();
    when(socket.getOutputStream()).thenReturn(out);

    GraphiteWriter writer = GraphiteWriter.builder().setHost("localhost").setPort(2003).build();
    writer.setPool(pool);

    writer.doWrite(dummyServer(), dummyQuery(), dummyResults());
    Mockito.verify(pool)
        .invalidateObject(Matchers.any(InetSocketAddress.class), Matchers.eq(socket));
    Mockito.verify(pool, Mockito.never())
        .returnObject(Matchers.any(InetSocketAddress.class), Matchers.eq(socket));
  }
Ejemplo n.º 4
0
  @Test
  public void booleanAsNumberWorks() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    GenericKeyedObjectPool<InetSocketAddress, Socket> pool = mock(GenericKeyedObjectPool.class);
    Socket socket = mock(Socket.class);
    when(pool.borrowObject(Matchers.any(InetSocketAddress.class))).thenReturn(socket);

    when(socket.getOutputStream()).thenReturn(out);

    GraphiteWriter writer =
        GraphiteWriter.builder().setHost("localhost").setPort(123).setBooleanAsNumber(true).build();
    writer.setPool(pool);

    writer.doWrite(dummyServer(), dummyQuery(), singleTrueResult());

    // check that the booleanAsNumber property was picked up from the JSON
    assertThat(out.toString())
        .startsWith("servers.host_example_net_4321.VerboseMemory.Verbose 1 0");
  }