flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From esam...@apache.org
Subject svn commit: r1156906 - in /incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume: sink/TestDefaultSinkFactory.java source/TestDefaultSourceFactory.java
Date Fri, 12 Aug 2011 00:48:19 GMT
Author: esammer
Date: Fri Aug 12 00:48:19 2011
New Revision: 1156906

URL: http://svn.apache.org/viewvc?rev=1156906&view=rev
Log:
- Added unit tests for Default{Source,Sink}Factory.

Added:
    incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/sink/TestDefaultSinkFactory.java
    incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/source/TestDefaultSourceFactory.java

Added: incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/sink/TestDefaultSinkFactory.java
URL: http://svn.apache.org/viewvc/incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/sink/TestDefaultSinkFactory.java?rev=1156906&view=auto
==============================================================================
--- incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/sink/TestDefaultSinkFactory.java
(added)
+++ incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/sink/TestDefaultSinkFactory.java
Fri Aug 12 00:48:19 2011
@@ -0,0 +1,69 @@
+package org.apache.flume.sink;
+
+import org.apache.flume.EventSink;
+import org.apache.flume.SinkFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestDefaultSinkFactory {
+
+  private SinkFactory sinkFactory;
+
+  @Before
+  public void setUp() {
+    sinkFactory = new DefaultSinkFactory();
+  }
+
+  @Test
+  public void testRegister() {
+    Assert.assertEquals(0, sinkFactory.getSinkNames().size());
+
+    sinkFactory.register("null", NullSink.class);
+
+    Assert.assertEquals(1, sinkFactory.getSinkNames().size());
+
+    Assert.assertEquals("null", sinkFactory.getSinkNames().iterator().next());
+  }
+
+  @Test
+  public void testCreate() throws InstantiationException {
+    Assert.assertEquals(0, sinkFactory.getSinkNames().size());
+
+    sinkFactory.register("null", NullSink.class);
+
+    Assert.assertEquals(1, sinkFactory.getSinkNames().size());
+
+    Assert.assertEquals("null", sinkFactory.getSinkNames().iterator().next());
+
+    EventSink sink = sinkFactory.create("null");
+
+    Assert.assertNotNull("Factory returned a null sink", sink);
+    Assert.assertTrue("Source isn't an instance of NullSink",
+        sink instanceof NullSink);
+
+    sink = sinkFactory.create("i do not exist");
+
+    Assert.assertNull("Factory returned a sink it shouldn't have", sink);
+  }
+
+  @Test
+  public void testUnregister() {
+    Assert.assertEquals(0, sinkFactory.getSinkNames().size());
+
+    Assert.assertTrue("Registering a source returned false",
+        sinkFactory.register("null", NullSink.class));
+
+    Assert.assertEquals(1, sinkFactory.getSinkNames().size());
+
+    Assert.assertEquals("null", sinkFactory.getSinkNames().iterator().next());
+
+    Assert.assertFalse("Unregistering an unknown sink returned true",
+        sinkFactory.unregister("i do not exist"));
+    Assert.assertTrue("Unregistering a sink returned false",
+        sinkFactory.unregister("null"));
+
+    Assert.assertEquals(0, sinkFactory.getSinkNames().size());
+  }
+
+}

Added: incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/source/TestDefaultSourceFactory.java
URL: http://svn.apache.org/viewvc/incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/source/TestDefaultSourceFactory.java?rev=1156906&view=auto
==============================================================================
--- incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/source/TestDefaultSourceFactory.java
(added)
+++ incubator/flume/branches/flume-728/flume-ng-core/src/test/java/org/apache/flume/source/TestDefaultSourceFactory.java
Fri Aug 12 00:48:19 2011
@@ -0,0 +1,72 @@
+package org.apache.flume.source;
+
+import org.apache.flume.EventSource;
+import org.apache.flume.SourceFactory;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class TestDefaultSourceFactory {
+
+  private SourceFactory sourceFactory;
+
+  @Before
+  public void setUp() {
+    sourceFactory = new DefaultSourceFactory();
+  }
+
+  @Test
+  public void testRegister() {
+    Assert.assertEquals(0, sourceFactory.getSourceNames().size());
+
+    sourceFactory.register("seq", SequenceGeneratorSource.class);
+
+    Assert.assertEquals(1, sourceFactory.getSourceNames().size());
+
+    Assert
+        .assertEquals("seq", sourceFactory.getSourceNames().iterator().next());
+  }
+
+  @Test
+  public void testCreate() throws InstantiationException {
+    Assert.assertEquals(0, sourceFactory.getSourceNames().size());
+
+    sourceFactory.register("seq", SequenceGeneratorSource.class);
+
+    Assert.assertEquals(1, sourceFactory.getSourceNames().size());
+
+    Assert
+        .assertEquals("seq", sourceFactory.getSourceNames().iterator().next());
+
+    EventSource source = sourceFactory.create("seq");
+
+    Assert.assertNotNull("Factory returned a null source", source);
+    Assert.assertTrue("Source isn't an instance of SequenceGeneratorSource",
+        source instanceof SequenceGeneratorSource);
+
+    source = sourceFactory.create("i do not exist");
+
+    Assert.assertNull("Factory returned a source it shouldn't have", source);
+  }
+
+  @Test
+  public void testUnregister() {
+    Assert.assertEquals(0, sourceFactory.getSourceNames().size());
+
+    Assert.assertTrue("Registering a source returned false",
+        sourceFactory.register("seq", SequenceGeneratorSource.class));
+
+    Assert.assertEquals(1, sourceFactory.getSourceNames().size());
+
+    Assert
+        .assertEquals("seq", sourceFactory.getSourceNames().iterator().next());
+
+    Assert.assertFalse("Unregistering an unknown source returned true",
+        sourceFactory.unregister("i do not exist"));
+    Assert.assertTrue("Unregistering a source returned false",
+        sourceFactory.unregister("seq"));
+
+    Assert.assertEquals(0, sourceFactory.getSourceNames().size());
+  }
+
+}



Mime
View raw message