Package org.apache.flume

Examples of org.apache.flume.Transaction


    context.putAll(parms);
    Configurables.configure(channel,  context);

    byte[] eventBody = new byte[405];

    Transaction tx = channel.getTransaction();
    tx.begin();
    channel.put(EventBuilder.withBody(eventBody));
    tx.commit();
    tx.close();
    channel.stop();
    parms.put("byteCapacity", "1500");
    context.putAll(parms);
    Configurables.configure(channel,  context);
    channel.start();
    tx = channel.getTransaction();
    tx.begin();
    channel.put(EventBuilder.withBody(eventBody));
    try {
      channel.put(EventBuilder.withBody(eventBody));
      tx.commit();
      Assert.fail();
    } catch ( ChannelException e ) {
      //success
      tx.rollback();
    } finally {
      tx.close();
    }

    channel.stop();
    parms.put("byteCapacity", "250");
    parms.put("byteCapacityBufferPercentage", "20");
    context.putAll(parms);
    Configurables.configure(channel,  context);
    channel.start();
    tx = channel.getTransaction();
    tx.begin();
    channel.put(EventBuilder.withBody(eventBody));
    tx.commit();
    tx.close();
    channel.stop();

    parms.put("byteCapacity", "300");
    context.putAll(parms);
    Configurables.configure(channel,  context);
    channel.start();
    tx = channel.getTransaction();
    tx.begin();
    try {
      for(int i = 0; i < 2; i++) {
        channel.put(EventBuilder.withBody(eventBody));
      }
      tx.commit();
      Assert.fail();
    } catch ( ChannelException e ) {
      //success
      tx.rollback();
    } finally {
      tx.close();
    }

    channel.stop();
    parms.put("byteCapacity", "3300");
    context.putAll(parms);
    Configurables.configure(channel,  context);
    channel.start();
    tx = channel.getTransaction();
    tx.begin();

    try {
      for(int i = 0; i < 15; i++) {
        channel.put(EventBuilder.withBody(eventBody));
      }
      tx.commit();
      Assert.fail();
    } catch ( ChannelException e ) {
      //success
      tx.rollback();
    } finally {
      tx.close();
    }
    channel.stop();
    parms.put("byteCapacity", "4000");
    context.putAll(parms);
    Configurables.configure(channel,  context);
    channel.start();
    tx = channel.getTransaction();
    tx.begin();

    try {
      for(int i = 0; i < 25; i++) {
        channel.put(EventBuilder.withBody(eventBody));
      }
      tx.commit();
      Assert.fail();
    } catch ( ChannelException e ) {
      //success
      tx.rollback();
    } finally {
      tx.close();
    }
    channel.stop();
  }
View Full Code Here


    sink.start();
    Assert.assertTrue(LifecycleController.waitForOneOf(sink,
        LifecycleState.START_OR_ERROR, 5000));

    Transaction transaction = channel.getTransaction();

    transaction.begin();
    for (int i = 0; i < 10; i++) {
      channel.put(event);
    }
    transaction.commit();
    transaction.close();

    for (int i = 0; i < 5; i++) {
      Sink.Status status = sink.process();
      Assert.assertEquals(Sink.Status.READY, status);
    }
View Full Code Here

    server.start();
    sink.start();
    Assert.assertTrue(LifecycleController.waitForOneOf(sink,
        LifecycleState.START_OR_ERROR, 5000));

    Transaction txn = channel.getTransaction();
    txn.begin();
    for (int i = 0; i < 4; i++) {
      channel.put(event);
    }
    txn.commit();
    txn.close();

    // should throw EventDeliveryException due to connect timeout
    delay.set(3000L); // because connect-timeout = 2000
    boolean threw = false;
    try {
View Full Code Here

    context.put("transactionCapacity", "1000");
    Configurables.configure(source, context);

    source.start();
    Thread.sleep(2000);
    Transaction transaction = channel.getTransaction();

    transaction.begin();
    Event event;

    FileOutputStream outputStream = new FileOutputStream(ouputFile);

    while ((event = channel.take()) != null) {
      outputStream.write(event.getBody());
      outputStream.write('\n');
    }

    outputStream.close();
    transaction.commit();
    transaction.close();

    Assert.assertEquals(FileUtils.checksumCRC32(inputFile),
      FileUtils.checksumCRC32(ouputFile));
  }
View Full Code Here

    Thread.sleep(500L); // let socket startup
    server.close();
    Thread.sleep(500L); // sleep a little to allow close occur

    Transaction transaction = channel.getTransaction();

    transaction.begin();
    for (int i = 0; i < 10; i++) {
      channel.put(event);
    }
    transaction.commit();
    transaction.close();

    for (int i = 0; i < 5; i++) {
      boolean threwException = false;
      try {
        sink.process();
View Full Code Here

    parms.put("byteCapacity", "2000");
    parms.put("byteCapacityBufferPercentage", "20");
    context.putAll(parms);
    Configurables.configure(channel,  context);

    Transaction tx = channel.getTransaction();
    tx.begin();
    //This line would cause a NPE without FLUME-1622.
    channel.put(EventBuilder.withBody(null));
    tx.commit();
    tx.close();

    tx = channel.getTransaction();
    tx.begin();
    channel.put(EventBuilder.withBody(new byte[0]));
    tx.commit();
    tx.close();


  }
View Full Code Here

                           ("tail -f " + filePath));

    Configurables.configure(source, context);
    source.start();

    Transaction transaction = channel.getTransaction();
    transaction.begin();

    for (int lineNumber = 0; lineNumber < 3; lineNumber++) {
        outputStream.write((eventBody).getBytes());
        outputStream.write(String.valueOf(lineNumber).getBytes());
        outputStream.write('\n');
        outputStream.flush();
    }
    outputStream.close();
    Thread.sleep(1500);

    for(int i = 0; i < 3; i++) {
      Event event = channel.take();
      assertNotNull(event);
      assertNotNull(event.getBody());
      assertEquals(eventBody + String.valueOf(i), new String(event.getBody()));
    }

    transaction.commit();
    transaction.close();
    source.stop();
    File file = new File(filePath);
    FileUtils.forceDelete(file);
  }
View Full Code Here

    sink.setChannel(channel);
    Configurables.configure(sink, context);
    sink.start();
    RpcClient firstClient = sink.getUnderlyingClient();
    Thread.sleep(6000);
    Transaction t = channel.getTransaction();
    t.begin();
    channel.put(EventBuilder.withBody("This is a test", Charset.defaultCharset()));
    t.commit();
    t.close();
    sink.process();
    // Make sure they are not the same object, connection should be reset
    Assert.assertFalse(firstClient == sink.getUnderlyingClient());
    sink.stop();
View Full Code Here

      Configurables.configure(source, context);
      source.start();
      // Some commands might take longer to complete, specially on Windows
      // or on slow environments (e.g. Travis CI).
      Thread.sleep(2500);
      Transaction transaction = channel.getTransaction();
      transaction.begin();
      try {
        List<String> output = Lists.newArrayList();
        Event event;
        while ((event = channel.take()) != null) {
          output.add(new String(event.getBody(), Charset.defaultCharset()));
        }
        transaction.commit();
//        System.out.println("command : " + command);
//        System.out.println("output : ");
//        for( String line : output )
//          System.out.println(line);
        Assert.assertArrayEquals(expectedOutput, output.toArray(new String[]{}));
      } finally {
        transaction.close();
        source.stop();
      }
    }
View Full Code Here

    sink.start();
    Assert.assertTrue(LifecycleController.waitForOneOf(sink,
        LifecycleState.START_OR_ERROR, 5000));

    Transaction transaction = channel.getTransaction();

    transaction.begin();
    for (int i = 0; i < 10; i++) {
      channel.put(event);
    }
    transaction.commit();
    transaction.close();

    for (int i = 0; i < 5; i++) {
      Sink.Status status = sink.process();
      Assert.assertEquals(Sink.Status.READY, status);
    }
View Full Code Here

TOP

Related Classes of org.apache.flume.Transaction

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.