flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From esam...@apache.org
Subject svn commit: r1160467 - in /incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability: ./ TestFileBasedWAL.java TestFileBasedWALManager.java TestFileBasedWALWriter.java
Date Mon, 22 Aug 2011 22:04:04 GMT
Author: esammer
Date: Mon Aug 22 22:04:04 2011
New Revision: 1160467

URL: http://svn.apache.org/viewvc?rev=1160467&view=rev
Log:
- Added unit tests for FileBaseWAL*.

Added:
    incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/
    incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/TestFileBasedWAL.java
    incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/TestFileBasedWALManager.java
    incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/TestFileBasedWALWriter.java

Added: incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/TestFileBasedWAL.java
URL: http://svn.apache.org/viewvc/incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/TestFileBasedWAL.java?rev=1160467&view=auto
==============================================================================
--- incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/TestFileBasedWAL.java
(added)
+++ incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/TestFileBasedWAL.java
Mon Aug 22 22:04:04 2011
@@ -0,0 +1,82 @@
+package org.apache.flume.durability;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestFileBasedWAL {
+
+  private File testBaseDirectory;
+  private FileBasedWAL wal;
+
+  @Before
+  public void setUp() {
+    testBaseDirectory = new File("/tmp/flume-fbw-tests/"
+        + System.currentTimeMillis() + "-" + Thread.currentThread().getId());
+
+    wal = new FileBasedWAL(testBaseDirectory);
+  }
+
+  @After
+  public void tearDown() throws IOException {
+    /*
+     * Google's Files.deleteRecursively(File) bails out if anything in the path
+     * is a symlink. On MOSX, /tmp is a symlink to /private/tmp so it breaks.
+     */
+    if (testBaseDirectory.exists()) {
+      for (File file : testBaseDirectory.listFiles()) {
+        file.delete();
+      }
+
+      testBaseDirectory.delete();
+    }
+
+    /*
+     * Attempt to delete the parent, but be happy with failure. This should
+     * allow parallel tests to occur.
+     */
+
+    testBaseDirectory.getParentFile().delete();
+  }
+
+  @Test
+  public void testInitialize() throws IOException {
+    testBaseDirectory.mkdirs();
+
+    wal.initialize();
+
+    Assert.assertTrue("WAL test directory doesn't exist:" + testBaseDirectory,
+        testBaseDirectory.exists());
+
+    Assert.assertTrue("Directory doesn't exist:" + wal.getOpenDirectory(), wal
+        .getOpenDirectory().exists());
+    Assert.assertTrue("Directory doesn't exist:" + wal.getPendingDirectory(),
+        wal.getPendingDirectory().exists());
+    Assert.assertTrue("Directory doesn't exist:" + wal.getSentDirectory(), wal
+        .getSentDirectory().exists());
+    Assert.assertTrue("Directory doesn't exist:" + wal.getCompleteDirectory(),
+        wal.getCompleteDirectory().exists());
+
+  }
+
+  @Test
+  public void testDirectories() throws IOException {
+    testBaseDirectory.mkdirs();
+
+    wal.initialize();
+
+    Assert.assertEquals(testBaseDirectory, wal.getBaseDirectory());
+    Assert.assertEquals(new File(testBaseDirectory, "open"),
+        wal.getOpenDirectory());
+    Assert.assertEquals(new File(testBaseDirectory, "pending"),
+        wal.getPendingDirectory());
+    Assert.assertEquals(new File(testBaseDirectory, "sent"),
+        wal.getSentDirectory());
+    Assert.assertEquals(new File(testBaseDirectory, "complete"),
+        wal.getCompleteDirectory());
+  }
+}

Added: incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/TestFileBasedWALManager.java
URL: http://svn.apache.org/viewvc/incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/TestFileBasedWALManager.java?rev=1160467&view=auto
==============================================================================
--- incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/TestFileBasedWALManager.java
(added)
+++ incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/TestFileBasedWALManager.java
Mon Aug 22 22:04:04 2011
@@ -0,0 +1,47 @@
+package org.apache.flume.durability;
+
+import java.io.File;
+
+import junit.framework.Assert;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestFileBasedWALManager {
+
+  private File testDirectory;
+  private FileBasedWALManager walManager;
+
+  @Before
+  public void setUp() {
+    testDirectory = new File("/tmp/flume-fbwm-tests", String.valueOf(System
+        .currentTimeMillis()));
+    walManager = new FileBasedWALManager();
+
+    testDirectory.mkdirs();
+
+    walManager.setDirectory(testDirectory);
+  }
+
+  @After
+  public void tearDown() {
+    if (testDirectory.exists()) {
+      for (File entry : testDirectory.listFiles()) {
+        entry.delete();
+      }
+
+      testDirectory.delete();
+    }
+  }
+
+  @Test
+  public void testGetWAL() {
+    FileBasedWAL wal = walManager.getWAL("test1");
+
+    Assert.assertNotNull(wal);
+    Assert.assertEquals(new File(testDirectory, "test1"),
+        wal.getBaseDirectory());
+  }
+
+}

Added: incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/TestFileBasedWALWriter.java
URL: http://svn.apache.org/viewvc/incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/TestFileBasedWALWriter.java?rev=1160467&view=auto
==============================================================================
--- incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/TestFileBasedWALWriter.java
(added)
+++ incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/durability/TestFileBasedWALWriter.java
Mon Aug 22 22:04:04 2011
@@ -0,0 +1,60 @@
+package org.apache.flume.durability;
+
+import java.io.File;
+import java.io.IOException;
+
+import junit.framework.Assert;
+
+import org.apache.flume.Event;
+import org.apache.flume.durability.FileBasedWALManager.FileBasedWALWriter;
+import org.apache.flume.event.SimpleEvent;
+import org.apache.flume.formatter.output.TextDelimitedOutputFormatter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestFileBasedWALWriter {
+
+  private File testDirectory;
+  private FileBasedWALWriter writer;
+
+  @Before
+  public void setUp() {
+    testDirectory = new File("/tmp/flume-fbww-tests", String.valueOf(System
+        .currentTimeMillis()));
+    writer = new FileBasedWALWriter();
+  }
+
+  @After
+  public void tearDown() {
+    if (testDirectory.exists()) {
+      for (File entry : testDirectory.listFiles()) {
+        entry.delete();
+      }
+
+      testDirectory.delete();
+    }
+
+    testDirectory.getParentFile().delete();
+  }
+
+  @Test
+  public void testWrite() throws IOException {
+    testDirectory.mkdirs();
+
+    Event event = new SimpleEvent();
+
+    event.setBody("Test event".getBytes());
+
+    writer.setFormatter(new TextDelimitedOutputFormatter());
+    writer.setFile(new File(testDirectory, "test.wal"));
+
+    writer.open();
+    writer.write(event);
+    writer.close();
+
+    Assert.assertTrue(writer.getFile().exists());
+    Assert.assertTrue(writer.getFile().length() > 0);
+  }
+
+}



Mime
View raw message