hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject hadoop git commit: HADOOP-10321. TestCompositeService should cover all enumerations of adding a service to a parent service. (Ray Chiang via kasha)
Date Tue, 01 Mar 2016 03:01:57 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 589b53763 -> c1855a33e


HADOOP-10321. TestCompositeService should cover all enumerations of adding a service to a
parent service. (Ray Chiang via kasha)

(cherry picked from commit 680f3fc02d0037d13c84a8b5c1a7e8729c0bcc94)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/c1855a33
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/c1855a33
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/c1855a33

Branch: refs/heads/branch-2
Commit: c1855a33ebdf9a9ba7630f025c33fcbbd7904f0c
Parents: 589b537
Author: Karthik Kambatla <kasha@cloudera.com>
Authored: Mon Feb 29 18:59:59 2016 -0800
Committer: Karthik Kambatla <kasha@cloudera.com>
Committed: Mon Feb 29 19:00:22 2016 -0800

----------------------------------------------------------------------
 hadoop-common-project/hadoop-common/CHANGES.txt |   3 +
 .../hadoop/service/TestCompositeService.java    | 480 +++++++++++++++++--
 2 files changed, 445 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/c1855a33/hadoop-common-project/hadoop-common/CHANGES.txt
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt
index eae216b..7c597f3 100644
--- a/hadoop-common-project/hadoop-common/CHANGES.txt
+++ b/hadoop-common-project/hadoop-common/CHANGES.txt
@@ -45,6 +45,9 @@ Release 2.9.0 - UNRELEASED
 
     HADOOP-12841. Update s3-related properties in core-default.xml. (Wei-Chiu Chuang via
lei)
 
+    HADOOP-10321. TestCompositeService should cover all enumerations of 
+    adding a service to a parent service. (Ray Chiang via kasha)
+
   BUG FIXES
 
     HADOOP-12605. Fix intermittent failure of TestIPC.testIpcWithReaderQueuing

http://git-wip-us.apache.org/repos/asf/hadoop/blob/c1855a33/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/service/TestCompositeService.java
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/service/TestCompositeService.java
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/service/TestCompositeService.java
index f2ede7d..9493740 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/service/TestCompositeService.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/service/TestCompositeService.java
@@ -332,40 +332,6 @@ public class TestCompositeService {
                  1, testService.getServices().size());
   }
 
-  @Test(timeout = 1000)
-  public void testAddInitedSiblingInInit() throws Throwable {
-    CompositeService parent = new CompositeService("parent");
-    BreakableService sibling = new BreakableService();
-    sibling.init(new Configuration());
-    parent.addService(new AddSiblingService(parent,
-                                            sibling,
-                                            STATE.INITED));
-    parent.init(new Configuration());
-    parent.start();
-    parent.stop();
-    assertEquals("Incorrect number of services",
-                 2, parent.getServices().size());
-  }
-
-  @Test(timeout = 1000)
-  public void testAddUninitedSiblingInInit() throws Throwable {
-    CompositeService parent = new CompositeService("parent");
-    BreakableService sibling = new BreakableService();
-    parent.addService(new AddSiblingService(parent,
-                                            sibling,
-                                            STATE.INITED));
-    parent.init(new Configuration());
-    try {
-      parent.start();
-      fail("Expected an exception, got " + parent);
-    } catch (ServiceStateException e) {
-      //expected
-    }
-    parent.stop();
-    assertEquals("Incorrect number of services",
-                 2, parent.getServices().size());
-  }
-
   @Test
   public void testRemoveService() {
     CompositeService testService = new CompositeService("TestService") {
@@ -393,6 +359,118 @@ public class TestCompositeService {
         2, testService.getServices().size());
   }
 
+  //
+  // Tests for adding child service to parent
+  //
+
+  @Test(timeout = 1000)
+  public void testAddUninitedChildBeforeInit() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService child = new BreakableService();
+    AddSiblingService.addChildToService(parent, child);
+    parent.init(new Configuration());
+    assertInState(STATE.INITED, child);
+    parent.start();
+    assertInState(STATE.STARTED, child);
+    parent.stop();
+    assertInState(STATE.STOPPED, child);
+  }
+
+  @Test(timeout = 1000)
+  public void testAddUninitedChildInInit() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService child = new BreakableService();
+    parent.init(new Configuration());
+    AddSiblingService.addChildToService(parent, child);
+    assertInState(STATE.NOTINITED, child);
+    try {
+      parent.start();
+      fail("Expected an exception, got " + parent);
+    } catch (ServiceStateException e) {
+      //expected
+    }
+    assertInState(STATE.NOTINITED, child);
+    parent.stop();
+    assertInState(STATE.NOTINITED, child);
+    assertEquals("Incorrect number of services",
+                 1, parent.getServices().size());
+  }
+
+  @Test(timeout = 1000)
+  public void testAddUninitedChildInStart() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService child = new BreakableService();
+    parent.init(new Configuration());
+    parent.start();
+    AddSiblingService.addChildToService(parent, child);
+    assertInState(STATE.NOTINITED, child);
+    parent.stop();
+    assertInState(STATE.NOTINITED, child);
+  }
+
+  @Test(timeout = 1000)
+  public void testAddUninitedChildInStop() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService child = new BreakableService();
+    parent.init(new Configuration());
+    parent.start();
+    parent.stop();
+    AddSiblingService.addChildToService(parent, child);
+    assertInState(STATE.NOTINITED, child);
+  }
+
+  @Test(timeout = 1000)
+  public void testAddInitedChildBeforeInit() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService child = new BreakableService();
+    child.init(new Configuration());
+    AddSiblingService.addChildToService(parent, child);
+    parent.init(new Configuration());
+    assertInState(STATE.INITED, child);
+    parent.start();
+    assertInState(STATE.STARTED, child);
+    parent.stop();
+    assertInState(STATE.STOPPED, child);
+  }
+
+  @Test(timeout = 1000)
+  public void testAddInitedChildInInit() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService child = new BreakableService();
+    child.init(new Configuration());
+    parent.init(new Configuration());
+    AddSiblingService.addChildToService(parent, child);
+    parent.start();
+    assertInState(STATE.STARTED, child);
+    parent.stop();
+    assertInState(STATE.STOPPED, child);
+  }
+
+  @Test(timeout = 1000)
+  public void testAddInitedChildInStart() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService child = new BreakableService();
+    child.init(new Configuration());
+    parent.init(new Configuration());
+    parent.start();
+    AddSiblingService.addChildToService(parent, child);
+    assertInState(STATE.INITED, child);
+    parent.stop();
+    assertInState(STATE.STOPPED, child);
+  }
+
+  @Test(timeout = 1000)
+  public void testAddInitedChildInStop() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService child = new BreakableService();
+    child.init(new Configuration());
+    parent.init(new Configuration());
+    parent.start();
+    parent.stop();
+    AddSiblingService.addChildToService(parent, child);
+    assertInState(STATE.INITED, child);
+  }
+
   @Test(timeout = 1000)
   public void testAddStartedChildBeforeInit() throws Throwable {
     CompositeService parent = new CompositeService("parent");
@@ -407,6 +485,49 @@ public class TestCompositeService {
       //expected
     }
     parent.stop();
+    assertEquals("Incorrect number of services",
+                 1, parent.getServices().size());
+  }
+
+  @Test(timeout = 1000)
+  public void testAddStartedChildInInit() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService child = new BreakableService();
+    child.init(new Configuration());
+    child.start();
+    parent.init(new Configuration());
+    AddSiblingService.addChildToService(parent, child);
+    parent.start();
+    assertInState(STATE.STARTED, child);
+    parent.stop();
+    assertInState(STATE.STOPPED, child);
+  }
+
+  @Test(timeout = 1000)
+  public void testAddStartedChildInStart() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService child = new BreakableService();
+    child.init(new Configuration());
+    child.start();
+    parent.init(new Configuration());
+    parent.start();
+    AddSiblingService.addChildToService(parent, child);
+    assertInState(STATE.STARTED, child);
+    parent.stop();
+    assertInState(STATE.STOPPED, child);
+  }
+
+  @Test(timeout = 1000)
+  public void testAddStartedChildInStop() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService child = new BreakableService();
+    child.init(new Configuration());
+    child.start();
+    parent.init(new Configuration());
+    parent.start();
+    parent.stop();
+    AddSiblingService.addChildToService(parent, child);
+    assertInState(STATE.STARTED, child);
   }
 
   @Test(timeout = 1000)
@@ -424,19 +545,92 @@ public class TestCompositeService {
       //expected
     }
     parent.stop();
+    assertEquals("Incorrect number of services",
+                 1, parent.getServices().size());
   }
 
   @Test(timeout = 1000)
-  public void testAddStartedSiblingInStart() throws Throwable {
+  public void testAddStoppedChildInInit() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService child = new BreakableService();
+    child.init(new Configuration());
+    child.start();
+    child.stop();
+    parent.init(new Configuration());
+    AddSiblingService.addChildToService(parent, child);
+    try {
+      parent.start();
+      fail("Expected an exception, got " + parent);
+    } catch (ServiceStateException e) {
+      //expected
+    }
+    assertInState(STATE.STOPPED, child);
+    parent.stop();
+    assertEquals("Incorrect number of services",
+                 1, parent.getServices().size());
+  }
+
+  @Test(timeout = 1000)
+  public void testAddStoppedChildInStart() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService child = new BreakableService();
+    child.init(new Configuration());
+    child.start();
+    child.stop();
+    parent.init(new Configuration());
+    parent.start();
+    AddSiblingService.addChildToService(parent, child);
+    parent.stop();
+  }
+
+  @Test(timeout = 1000)
+  public void testAddStoppedChildInStop() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService child = new BreakableService();
+    child.init(new Configuration());
+    child.start();
+    child.stop();
+    parent.init(new Configuration());
+    parent.start();
+    parent.stop();
+    AddSiblingService.addChildToService(parent, child);
+  }
+
+  //
+  // Tests for adding sibling service to parent
+  //
+
+  @Test(timeout = 1000)
+  public void testAddUninitedSiblingBeforeInit() throws Throwable {
     CompositeService parent = new CompositeService("parent");
     BreakableService sibling = new BreakableService();
-    sibling.init(new Configuration());
-    sibling.start();
     parent.addService(new AddSiblingService(parent,
                                             sibling,
-                                            STATE.STARTED));
+                                            STATE.NOTINITED));
     parent.init(new Configuration());
+    assertInState(STATE.NOTINITED, sibling);
     parent.start();
+    assertInState(STATE.NOTINITED, sibling);
+    parent.stop();
+    assertInState(STATE.NOTINITED, sibling);
+    assertEquals("Incorrect number of services",
+                 1, parent.getServices().size());
+  }
+
+  @Test(timeout = 1000)
+  public void testAddUninitedSiblingInInit() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService sibling = new BreakableService();
+    parent.addService(new AddSiblingService(parent,
+                                            sibling,
+                                            STATE.INITED));
+    parent.init(new Configuration());
+    try {
+      parent.start();
+      fail("Expected an exception, got " + parent);
+    } catch (ServiceStateException e) {
+      //expected
+    }
     parent.stop();
     assertEquals("Incorrect number of services",
                  2, parent.getServices().size());
@@ -452,12 +646,115 @@ public class TestCompositeService {
     parent.init(new Configuration());
     assertInState(STATE.NOTINITED, sibling);
     parent.start();
+    assertInState(STATE.NOTINITED, sibling);
+    parent.stop();
+    assertInState(STATE.NOTINITED, sibling);
+    assertEquals("Incorrect number of services",
+                 2, parent.getServices().size());
+  }
+
+  @Test(timeout = 1000)
+  public void testAddUninitedSiblingInStop() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService sibling = new BreakableService();
+    parent.addService(new AddSiblingService(parent,
+                                            sibling,
+                                            STATE.STOPPED));
+    parent.init(new Configuration());
+    assertInState(STATE.NOTINITED, sibling);
+    parent.start();
+    assertInState(STATE.NOTINITED, sibling);
+    parent.stop();
+    assertInState(STATE.NOTINITED, sibling);
+    assertEquals("Incorrect number of services",
+                 2, parent.getServices().size());
+  }
+
+  @Test(timeout = 1000)
+  public void testAddInitedSiblingBeforeInit() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService sibling = new BreakableService();
+    sibling.init(new Configuration());
+    parent.addService(new AddSiblingService(parent,
+                                            sibling,
+                                            STATE.NOTINITED));
+    parent.init(new Configuration());
+    assertInState(STATE.INITED, sibling);
+    parent.start();
+    assertInState(STATE.INITED, sibling);
+    parent.stop();
+    assertInState(STATE.INITED, sibling);
+    assertEquals("Incorrect number of services",
+                 1, parent.getServices().size());
+  }
+
+  @Test(timeout = 1000)
+  public void testAddInitedSiblingInInit() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService sibling = new BreakableService();
+    sibling.init(new Configuration());
+    parent.addService(new AddSiblingService(parent,
+                                            sibling,
+                                            STATE.INITED));
+    parent.init(new Configuration());
+    assertInState(STATE.INITED, sibling);
+    parent.start();
+    assertInState(STATE.STARTED, sibling);
+    parent.stop();
+    assertInState(STATE.STOPPED, sibling);
+    assertEquals("Incorrect number of services",
+                 2, parent.getServices().size());
+  }
+
+  @Test(timeout = 1000)
+  public void testAddInitedSiblingInStart() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService sibling = new BreakableService();
+    sibling.init(new Configuration());
+    parent.addService(new AddSiblingService(parent,
+                                            sibling,
+                                            STATE.STARTED));
+    parent.init(new Configuration());
+    assertInState(STATE.INITED, sibling);
+    parent.start();
+    assertInState(STATE.INITED, sibling);
     parent.stop();
+    assertInState(STATE.STOPPED, sibling);
     assertEquals("Incorrect number of services",
                  2, parent.getServices().size());
   }
 
   @Test(timeout = 1000)
+  public void testAddInitedSiblingInStop() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService sibling = new BreakableService();
+    sibling.init(new Configuration());
+    parent.addService(new AddSiblingService(parent,
+                                            sibling,
+                                            STATE.STOPPED));
+    parent.init(new Configuration());
+  }
+
+  @Test(timeout = 1000)
+  public void testAddStartedSiblingBeforeInit() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService sibling = new BreakableService();
+    sibling.init(new Configuration());
+    sibling.start();
+    parent.addService(new AddSiblingService(parent,
+                                            sibling,
+                                            STATE.NOTINITED));
+    parent.init(new Configuration());
+    assertInState(STATE.STARTED, sibling);
+    parent.start();
+    assertInState(STATE.STARTED, sibling);
+    parent.stop();
+    assertInState(STATE.STARTED, sibling);
+    assertEquals("Incorrect number of services",
+                 1, parent.getServices().size());
+  }
+
+  @Test(timeout = 1000)
   public void testAddStartedSiblingInInit() throws Throwable {
     CompositeService parent = new CompositeService("parent");
     BreakableService sibling = new BreakableService();
@@ -471,9 +768,29 @@ public class TestCompositeService {
     parent.start();
     assertInState(STATE.STARTED, sibling);
     parent.stop();
+    assertInState(STATE.STOPPED, sibling);
     assertEquals("Incorrect number of services",
                  2, parent.getServices().size());
+  }
+
+
+  @Test(timeout = 1000)
+  public void testAddStartedSiblingInStart() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService sibling = new BreakableService();
+    sibling.init(new Configuration());
+    sibling.start();
+    parent.addService(new AddSiblingService(parent,
+                                            sibling,
+                                            STATE.STARTED));
+    parent.init(new Configuration());
+    assertInState(STATE.STARTED, sibling);
+    parent.start();
+    assertInState(STATE.STARTED, sibling);
+    parent.stop();
     assertInState(STATE.STOPPED, sibling);
+    assertEquals("Incorrect number of services",
+                 2, parent.getServices().size());
   }
 
   @Test(timeout = 1000)
@@ -486,8 +803,95 @@ public class TestCompositeService {
                                             sibling,
                                             STATE.STOPPED));
     parent.init(new Configuration());
+    assertInState(STATE.STARTED, sibling);
+    parent.start();
+    assertInState(STATE.STARTED, sibling);
+    parent.stop();
+    assertInState(STATE.STARTED, sibling);
+    assertEquals("Incorrect number of services",
+                 2, parent.getServices().size());
+  }
+
+  @Test(timeout = 1000)
+  public void testAddStoppedSiblingBeforeInit() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService sibling = new BreakableService();
+    sibling.init(new Configuration());
+    sibling.start();
+    sibling.stop();
+    parent.addService(new AddSiblingService(parent,
+                                            sibling,
+                                            STATE.NOTINITED));
+    parent.init(new Configuration());
+    assertInState(STATE.STOPPED, sibling);
     parent.start();
+    assertInState(STATE.STOPPED, sibling);
     parent.stop();
+    assertInState(STATE.STOPPED, sibling);
+    assertEquals("Incorrect number of services",
+                 1, parent.getServices().size());
+  }
+
+  @Test(timeout = 1000)
+  public void testAddStoppedSiblingInInit() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService sibling = new BreakableService();
+    sibling.init(new Configuration());
+    sibling.start();
+    sibling.stop();
+    parent.addService(new AddSiblingService(parent,
+                                            sibling,
+                                            STATE.INITED));
+    parent.init(new Configuration());
+    assertInState(STATE.STOPPED, sibling);
+    try {
+      parent.start();
+      fail("Expected an exception, got " + parent);
+    } catch (ServiceStateException e) {
+      //expected
+    }
+    parent.stop();
+    assertInState(STATE.STOPPED, sibling);
+    assertEquals("Incorrect number of services",
+                 2, parent.getServices().size());
+  }
+
+  @Test(timeout = 1000)
+  public void testAddStoppedSiblingInStart() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService sibling = new BreakableService();
+    sibling.init(new Configuration());
+    sibling.start();
+    sibling.stop();
+    parent.addService(new AddSiblingService(parent,
+                                            sibling,
+                                            STATE.STARTED));
+    parent.init(new Configuration());
+    assertInState(STATE.STOPPED, sibling);
+    parent.start();
+    assertInState(STATE.STOPPED, sibling);
+    parent.stop();
+    assertInState(STATE.STOPPED, sibling);
+    assertEquals("Incorrect number of services",
+                 2, parent.getServices().size());
+  }
+
+  @Test(timeout = 1000)
+  public void testAddStoppedSiblingInStop() throws Throwable {
+    CompositeService parent = new CompositeService("parent");
+    BreakableService sibling = new BreakableService();
+    sibling.init(new Configuration());
+    sibling.start();
+    sibling.stop();
+    parent.addService(new AddSiblingService(parent,
+                                            sibling,
+                                            STATE.STOPPED));
+    parent.init(new Configuration());
+    assertInState(STATE.STOPPED, sibling);
+    parent.start();
+    assertInState(STATE.STOPPED, sibling);
+    parent.stop();
+    assertInState(STATE.STOPPED, sibling);
     assertEquals("Incorrect number of services",
                  2, parent.getServices().size());
   }


Mime
View raw message