From 2aa8aee407d3ba221e1fd24e143b916b2d0be3c0 Mon Sep 17 00:00:00 2001
From: Gary Williams <gary.williams@forgerock.com>
Date: Wed, 28 Mar 2012 14:02:43 +0000
Subject: [PATCH] refactor replication functional tests to be one test per function

---
 opends/tests/staf-tests/functional-tests/testcases/replication/failover/failover.xml |  617 ++++++++++----------------------------------------------
 1 files changed, 110 insertions(+), 507 deletions(-)

diff --git a/opends/tests/staf-tests/functional-tests/testcases/replication/failover/failover.xml b/opends/tests/staf-tests/functional-tests/testcases/replication/failover/failover.xml
index 3b9a4c3..1554258 100644
--- a/opends/tests/staf-tests/functional-tests/testcases/replication/failover/failover.xml
+++ b/opends/tests/staf-tests/functional-tests/testcases/replication/failover/failover.xml
@@ -7,540 +7,143 @@
  ! Common Development and Distribution License, Version 1.0 only
  ! (the "License").  You may not use this file except in compliance
  ! with the License.
- !
+ ! 
  ! You can obtain a copy of the license at
- ! trunk/opends/resource/legal-notices/OpenDS.LICENSE
- ! or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ ! trunk/opends/resource/legal-notices/CDDLv1_0.txt
+ ! or http://forgerock.org/license/CDDLv1.0.html.
  ! See the License for the specific language governing permissions
  ! and limitations under the License.
- !
+ ! 
  ! When distributing Covered Code, include this CDDL HEADER in each
  ! file and include the License file at
- ! trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
+ ! trunk/opends/resource/legal-notices/CDDLv1_0.txt.  If applicable,
  ! add the following below this CDDL HEADER, with the fields enclosed
  ! by brackets "[]" replaced with your own identifying information:
  !      Portions Copyright [yyyy] [name of copyright owner]
  !
  ! CDDL HEADER END
  !
- !      Copyright 2007-2010 Sun Microsystems, Inc.
- !      Portions Copyright 2011-2012 ForgeRock AS.
+ !      Copyright 2012 ForgeRock AS.
  ! -->
 <stax>
-
   <defaultcall function="replication_failover"/>
-
-  <function name="replication_failover">
-
+  <function name="replication_failover" scope="local">
     <sequence>
-
-      <block name="'failover'">
-
-        <sequence>
-            
-          <script>
-            if not CurrentTestPath.has_key('group'):
-              CurrentTestPath['group']='replication'                 
-            CurrentTestPath['suite']=STAXCurrentBlock
-          </script>            
-
-          <call function="'testSuite_Preamble'"/>
-
-          <!--- Test Suite information
-          #@TestSuiteName       Replication Failover Tests
-          #@TestSuitePurpose    Verify that the failover of a replication server does not affect replication.
-          #@TestSuiteID         Failover Tests
-          #@TestSuiteGroup      Failover
-          #@TestGroup           Replication
-          #@TestScript          replication_failover.xml
-          #@TestHTMLLink        http://opends.dev.java.net/
-          -->
-            
-                                                                        
-          <import machine="STAF_LOCAL_HOSTNAME"
-            file="'%s/testcases/replication/replication_setup.xml' % (TESTS_DIR)"/>
-          <call function="'replication_setup'">
-            {  'topologyFile' : '%s/3server_topology.txt' % REPLICATION_CONFIG_DIR ,
-               'label'        : 'Replication Failover' }
-          </call>
-                                    
-          <script>
-            synchroSuffix = master.getSynchronizedSuffixList()[0].getSuffixDn()      
-          </script>            
-
-            
-          <!-- Load entries into "master" server -->                                
-          <!-- Stop "master" Directory Server -->
-          <call function="'StopDsWithScript'">
-            { 'location'    : masterHost,
-              'dsPath'      : masterPath,
-              'dsHost'      : masterHost,
-              'dsAdminPort' : master.getAdminPort(),
-              'dsBindDN'    : master.getRootDn(),
-              'dsBindPwd'   : master.getRootPwd(),
-              'noOfLoops'   : 30
-            }
-          </call>
+      <block name="'replication_failover'">
+        <try>
+          <sequence>
+            <script>
+              CurrentTestPath['group'] = 'replication'        
+              CurrentTestPath['suite'] = 'failover'
               
-          <!-- Import data into "master" Directory Server -->
-          <call function="'ImportLdifWithScript'">
-            { 'location'     : masterHost,
-              'dsPath'       : masterPath,
-              'backEnd'      : DIRECTORY_INSTANCE_BE,
-              'ldifFile'     : '%s/replication/Example.ldif' % masterDataDir
-            }
-          </call>
+              _group=CurrentTestPath['group']
+              _groupdir='%s/testcases/%s' % (TESTS_DIR,_group)
+              _label = 'Replication Failover'
+            </script>
 
-          <!-- Start the Directory Server -->
-          <call function="'StartDsWithScript'">
-            { 'location'  : masterHost,
-              'dsPath'    : masterPath
-            }
-          </call>
-              
-          <!-- Wait for DS to start -->
-          <call function="'isAlive'">
-            { 'location'         : masterHost,
-              'dsPath'           : masterPath,
-              'dsInstanceHost'   : masterHost,
-              'dsInstancePort'   : master.getPort() ,
-              'dsInstanceDn'     : master.getRootDn() ,
-              'dsInstancePswd'   : master.getRootPwd() ,
-              'noOfLoops'        : 10 ,
-              'noOfMilliSeconds' : 2000
-            }
-          </call>                                                                                
-            
-          <!-- Initialise the servers in the topology -->
-<!--
-          <call function="'initializeReplication'">
-            { 'location'  :  clientHost,
-              'dsPath'  :  clientPath,
-              'sourceInstanceHost'      :  masterHost,
-              'sourceInstanceAdminPort' :  master.getAdminPort(),
-              'replicationDnList'       :  ['o=example']
-            }
-          </call>            
--->    
-          <iterate var="server" in="consumerList">                                    
-            <!-- Perform the total update -->
-            <call function="'initializeReplication'">
-              { 'location'                :  clientHost,
-                'dsPath'                  :  clientPath,
-                'dsInstanceHost'          :  server.getHostname(),
-                'dsInstanceAdminPort'     :  server.getAdminPort(),
-                'sourceInstanceHost'      :  masterHost,
-                'sourceInstanceAdminPort' :  master.getAdminPort(),
-                'replicationDnList'       :  ['o=example']
-              }
-            </call>
-          </iterate>            
-            
-                        
-          <!--- Test Case information
-          #@TestMarker          Replication Failover Tests
-          #@TestName            Replication: Failover: One server down (stopped)
-          #@TestID                  One server down (stopped)
-          #@TestPurpose        Check replication when one server is off-line
-          #@TestPreamble
-          #@TestSteps
-          #@TestPostamble
-          #@TestResult
-          -->               
-          <testcase name="getTestCaseName('One server down (stopped)')">
-            <sequence>            
-              <call function="'testCase_Preamble'"/>
-              <message>
-                 'Replication: Failover: One server down (stopped). Check replication when one server is off-line '
-              </message>
-                             
-              <iterate var="server" in="_topologyServerList" indexvar="i">
-                <sequence>
-                    
-                  <script>
-                    serverPath = '%s/%s' % (server.getDir(), OPENDSNAME)
-                    nbOfServers = len(_topologyServerList)
-                    nextServer = _topologyServerList[(i + 1) % nbOfServers]
-                    nextServerPath = '%s/%s' % (nextServer.getDir(), OPENDSNAME)
-                    userDn = 'uid=iabizen-%s, ou=People, %s' % (i, synchroSuffix)
-                    
-                    if globalSplitServers:
-                      replServer = _topologyReplServerList[i]
-                    else:
-                      replServer = server
-
-                    replServerPath = '%s/%s' % (replServer.getDir(), OPENDSNAME)
-                  </script>
-                    
-                  <!-- Stop server (simulate failover?) -->
-                  <call function="'StopDsWithScript'">
-                    { 'location'    :  server.getHostname(),
-                      'dsPath'      :  serverPath,
-                      'dsHost'      :  server.getHostname(),
-                      'dsAdminPort' :  server.getAdminPort(),
-                      'dsBindDN'    :  server.getRootDn(),
-                      'dsBindPwd'   :  server.getRootPwd(),
-                      'noOfLoops'   : 30
-                    }
-                  </call>
-                  <if expr="globalSplitServers">
-                    <call function="'StopDsWithScript'">
-                      { 'location'    :  replServer.getHostname(),
-                        'dsPath'      :  replServerPath,
-                        'dsHost'      :  replServer.getHostname(),
-                        'dsAdminPort' :  replServer.getAdminPort(),
-                        'dsBindDN'    :  replServer.getRootDn(),
-                        'dsBindPwd'   :  replServer.getRootPwd(),
-                        'noOfLoops'   : 30
-                      }
-                    </call>
-                  </if>
-                    
-                  <!-- Add entry to one of the other servers -->
-                  <script>
-                    listAttr = []
-                    listAttr.append('objectclass:top')
-                    listAttr.append('objectclass:organizationalperson')
-                    listAttr.append('objectclass:inetorgperson')
-                    listAttr.append('objectclass:person')
-                    listAttr.append('givenname:Izen-%s' % i)
-                    listAttr.append('sn:Abizen-%s' % i)
-                    listAttr.append('cn:Izen-%s Abizen-%s' % (i, i))
-                  </script>
-          
-                  <call function="'addAnEntry'">
-                    { 'location'       :  nextServer.getHostname(),
-                      'dsPath'         :  nextServerPath,
-                      'dsInstanceHost' :  nextServer.getHostname(),
-                      'dsInstancePort' :  nextServer.getPort(),
-                      'dsInstanceDn'   :  nextServer.getRootDn(),
-                      'dsInstancePswd' :  nextServer.getRootPwd(),
-                      'DNToAdd'        :  userDn,
-                      'listAttributes' : listAttr,
-                      'expectedRC'     :  0
-                    }
-                  </call>
-                                                                                
-                  <!-- Start the server again -->
-                  <call function="'StartDsWithScript'">
-                    { 'location'  :  server.getHostname(),
-                      'dsPath'    :  serverPath
-                    }
-                  </call>
-                  <if expr="globalSplitServers">
-                    <call function="'StartDsWithScript'">
-                      { 'location'    :  replServer.getHostname(),
-                        'dsPath'      :  replServerPath
-                      }
-                    </call>
-                  </if>
-                </sequence>                  
-              </iterate>
-                                        
-                
-              <!-- Verify the synchronization of the trees among the servers in the topology -->          
-              <call function="'verifyTrees'">
-                [ clientHost, clientPath, master, consumerList, synchroSuffix ]
-              </call> 
-                                
-              <call function="'testCase_Postamble'"/>
-            </sequence>
-          </testcase>                     
-          
-
-
-          <!--- Test Case information
-          #@TestMarker          Replication Failover Tests
-          #@TestName            Replication: Failover: All but one servers down (stopped)
-          #@TestID                  All but one servers down (stopped)
-          #@TestPurpose        Check replication when all but one servers are off-line
-          #@TestPreamble
-          #@TestSteps
-          #@TestPostamble
-          #@TestResult
-          -->               
-          <testcase name="getTestCaseName('All but one servers down (stopped)')">
-            <sequence>            
-              <call function="'testCase_Preamble'"/>
-              <message>
-                 'Replication: Failover: All but one servers down (stopped). Check replication when all but one servers are off-line'
-              </message>
-
-              <!-- Stop the "consumer" servers -->
-              <call function="'stopServers'">
-                [consumerList, 30]
-              </call>
-              <if expr="globalSplitServers">
-                <call function="'stopServers'">
-                  [_topologyReplServerList[1:], 30]
-                </call>
-              </if>
- 
-                    
-              <!-- Add entry to master servers -->
-              <script>
-                userDn = 'uid=iabizen-berri, ou=People, %s' % synchroSuffix
+            <!--- Test Suite information
+            #@TestSuiteName       Replication Failover Tests
+            #@TestSuitePurpose    Verify that the total-update operations are replicated
+                                  correctly between two servers.
+            #@TestSuiteID         Failover Tests
+            #@TestSuiteGroup      Failover
+            #@TestGroup           Replication
+            #@TestScript          replication_failover.xml
+            #@TestHTMLLink        http://www.forgerock.org/
+              -->
                   
-                listAttr = []
-                listAttr.append('objectclass:top')
-                listAttr.append('objectclass:organizationalperson')
-                listAttr.append('objectclass:inetorgperson')
-                listAttr.append('objectclass:person')
-                listAttr.append('givenname:Izen-berri')
-                listAttr.append('sn:Abizen-berri')
-                listAttr.append('cn:Izen-berri Abizen-berri')
-              </script>
-          
-              <call function="'addAnEntry'">
-                { 'location'       :  masterHost,
-                  'dsPath'         :  masterPath,
-                  'dsInstanceHost' :  masterHost,
-                  'dsInstancePort' :  master.getPort(),
-                  'dsInstanceDn'   :  master.getRootDn(),
-                  'dsInstancePswd' :  master.getRootPwd(),
-                  'DNToAdd'        :  userDn,
-                  'listAttributes' :  listAttr,
-                  'expectedRC'     :  0
-                }
-              </call>
+            <call function="'testSuite_Preamble'"/>
 
-              <!-- Start the "consumer" servers -->
-              <call function="'startServers'">
-                [consumerList]
-              </call>
-              <if expr="globalSplitServers">
-                <call function="'startServers'">
-                  [_topologyReplServerList[1:]]
+            <try>
+              <sequence> 
+
+                <import machine="STAF_LOCAL_HOSTNAME"
+                  file="'%s/testcases/replication/replication_setup.xml' % (TESTS_DIR)"/>
+                <call function="'replication_setup'">
+                  {  'topologyFile' : '%s/3server_topology.txt' % REPLICATION_CONFIG_DIR ,
+                     'label'        : _label }
                 </call>
-              </if>
-                                  
-                
-              <!-- Verify the synchronization of the trees among the servers in the topology -->          
-              <call function="'verifyTrees'">
-                [ clientHost, clientPath, master, consumerList, synchroSuffix ]
-              </call> 
+
+                <!-- List of Import of Test Functions -->
+                <script>
+                  importList=[]
+                  importList.append('failover/failover_tests')
+                </script>
+
+                <!-- Import the files for this test suite -->
+                <iterate var="_import" in="importList">
+                  <import machine="STAF_LOCAL_HOSTNAME"
+                    file="'%s/%s.xml' % (_groupdir,_import)"/>
+                </iterate>                                                                       
+
+                <!-- Specific to replication tests -->
+                <script>
+                  msg1 = 'Replication: Failover:'
+                </script>
+                                                    
+                <!-- List of Test Cases -->
+                <script>
+                  testsList=[]
+                  testsList.append('replication_failover_001')
+                  testsList.append('replication_failover_002')
+                  testsList.append('replication_failover_003')
+                  testsList.append('replication_failover_004')
+                  testsList.append('replication_failover_005')
+                </script>
+
+                <!-- Execute the Tests -->
+                <iterate var="__test" in="testsList">
+                  <sequence>
+                    <call function="'%s' % (__test)" />
+                  </sequence>
+                </iterate>                
                                 
-              <call function="'testCase_Postamble'"/>
-            </sequence>
-          </testcase>                     
-                                                
+              </sequence>
 
-
-
-
-          <!--- Test Case information
-          #@TestMarker          Replication Failover Tests
-          #@TestName            Replication: Failover: One server down (killed)
-          #@TestID                  One server down (killed)
-          #@TestPurpose        Check replication when one server fails
-          #@TestPreamble
-          #@TestSteps
-          #@TestPostamble
-          #@TestResult
-          -->               
-          <testcase name="getTestCaseName('One server down (killed)')">
-            <sequence>            
-              <call function="'testCase_Preamble'"/>
-              <message>
-                 'Replication: Failover: One server down (killed). Check replication when one server fails'
-              </message>
-                             
-              <iterate var="server" in="_topologyServerList" indexvar="i">
+              <catch exception="'STAFException.TestSuite.SetupException'">
                 <sequence>
-                    
-                  <script>
-                    serverPath = '%s/%s' % (server.getDir(), OPENDSNAME)
-                    nbOfServers = len(_topologyServerList)
-                    nextServer = _topologyServerList[(i + 1) % nbOfServers]
-                    nextServerPath = '%s/%s' % (nextServer.getDir(), OPENDSNAME)
-                    userDn = 'uid=ideiturak-%s, ou=People, %s' % (i, synchroSuffix)
-                    
-                    if globalSplitServers:
-                      replServer = _topologyReplServerList[i]
-                    else:
-                      replServer = server
-
-                    replServerPath = '%s/%s' % (replServer.getDir(), OPENDSNAME)
-                  </script>
-                    
-                  <!-- Kill server (simulate failover?) -->
-                  <call function="'killDs'">
-                    { 'location'  :  server.getHostname(),
-                      'dsPath'    :  serverPath
-                    }
-                  </call>
-                  <if expr="globalSplitServers">
-                    <call function="'killDs'">
-                      { 'location'  :  replServer.getHostname(),
-                        'dsPath'    :  replServerPath
-                      }
-                    </call>
-                  </if>
-                    
-                  <!-- Add entry to one of the other servers -->
-                  <script>
-                    listAttr = []
-                    listAttr.append('objectclass:top')
-                    listAttr.append('objectclass:organizationalperson')
-                    listAttr.append('objectclass:inetorgperson')
-                    listAttr.append('objectclass:person')
-                    listAttr.append('givenname:Izen-%s' % i)
-                    listAttr.append('sn:Deiturak-%s' % i)
-                    listAttr.append('cn:Izen-%s Deiturak-%s' % (i, i))
-                  </script>
-          
-                  <call function="'addAnEntry'">
-                    { 'location'       :  nextServer.getHostname(),
-                      'dsPath'         :  nextServerPath,
-                      'dsInstanceHost' :  nextServer.getHostname(),
-                      'dsInstancePort' :  nextServer.getPort(),
-                      'dsInstanceDn'   :  nextServer.getRootDn(),
-                      'dsInstancePswd' :  nextServer.getRootPwd(),
-                      'DNToAdd'        :  userDn,
-                      'listAttributes' : listAttr,
-                      'expectedRC'     :  0
-                    }
-                  </call>
-                                                                                
-                  <!-- Start the server again -->
-                  <call function="'StartDsWithScript'">
-                    { 'location'  :  server.getHostname(),
-                      'dsPath'    :  serverPath
-                    }
-                  </call>
-                  <if expr="globalSplitServers">
-                    <call function="'StartDsWithScript'">
-                      { 'location'    :  replServer.getHostname(),
-                        'dsPath'      :  replServerPath
-                      }
-                    </call>
-                  </if>
-                  
-                </sequence>                  
-              </iterate>
-                                        
-                
-              <!-- Verify the synchronization of the trees among the servers in the topology -->          
-              <call function="'verifyTrees'">
-                [ clientHost, clientPath, master, consumerList, synchroSuffix ]
-              </call> 
-                                
-              <call function="'testCase_Postamble'"/>
-            </sequence>
-          </testcase>                     
-          
-
-
-          <!--- Test Case information
-          #@TestMarker          Replication Failover Tests
-          #@TestName            Replication: Failover: All but one servers down (killed)
-          #@TestID                  One server down (killed)
-          #@TestPurpose        Check replication when all but one servers fail
-          #@TestPreamble
-          #@TestSteps
-          #@TestPostamble
-          #@TestResult
-          -->               
-          <testcase name="getTestCaseName('All but one servers down (killed)')">
-            <sequence>            
-              <call function="'testCase_Preamble'"/>
-              <message>
-                 'Replication: Failover: All but one servers down (killed). Check replication when all but one servers fail'
-              </message>
-                 
-              <paralleliterate var="server" in="consumerList" indexvar="i">
-                <sequence>
-                  <script>
-                    serverPath = '%s/%s' % (server.getDir(), OPENDSNAME)
-                    
-                    if globalSplitServers:
-                      replServer = _topologyReplServerList[i+1]
-                    else:
-                      replServer = server
-
-                    replServerPath = '%s/%s' % (replServer.getDir(), OPENDSNAME)
-                  </script>
-                    
-                  <!-- Kill server (simulate failover?) -->
-                  <call function="'killDs'">
-                    { 'location'  :  server.getHostname(),
-                      'dsPath'    :  serverPath
-                    }
-                  </call>
-                  <if expr="globalSplitServers">
-                    <call function="'killDs'">
-                      { 'location'  :  replServer.getHostname(),
-                        'dsPath'    :  replServerPath
-                      }
-                    </call>
-                  </if>
+                  <message log="1" level="'fatal'">
+                    'Setup of test suite failed.'
+                  </message>
+                  <rethrow/>
                 </sequence>
-              </paralleliterate>
- 
-                    
-              <!-- Add entry to master servers -->
-              <script>
-                userDn = 'uid=ideitura-berriak, ou=People, %s' % synchroSuffix
-                  
-                listAttr = []
-                listAttr.append('objectclass:top')
-                listAttr.append('objectclass:organizationalperson')
-                listAttr.append('objectclass:inetorgperson')
-                listAttr.append('objectclass:person')
-                listAttr.append('givenname:Izen-berri')
-                listAttr.append('sn:Deitura-berriak')
-                listAttr.append('cn:Izen-berri Deitura-berriak')
-              </script>
+              </catch>
+  
+              <finally>
+                <message>'Test Cases Completed.'</message>
+              </finally>
+
+            </try>
+
+          </sequence>
           
-              <call function="'addAnEntry'">
-                { 'location'       :  masterHost,
-                  'dsPath'         :  masterPath,
-                  'dsInstanceHost' :  masterHost,
-                  'dsInstancePort' :  master.getPort(),
-                  'dsInstanceDn'   :  master.getRootDn(),
-                  'dsInstancePswd' :  master.getRootPwd(),
-                  'DNToAdd'        :  userDn,
-                  'listAttributes' : listAttr,
-                  'expectedRC'     :  0
-                }
-              </call>
-
-              <!-- Start the "consumer" servers -->
-              <call function="'startServers'">
-                [consumerList]
-              </call>
-              <if expr="globalSplitServers">
-                <call function="'startServers'">
-                  [_topologyReplServerList[1:]]
-                </call>
-              </if>
-                                        
-                
-              <!-- Verify the synchronization of the trees among the servers in the topology -->          
-              <call function="'verifyTrees'">
-                [ clientHost, clientPath, master, consumerList, synchroSuffix ]
-              </call> 
-                                
-              <call function="'testCase_Postamble'"/>
+          <finally>
+            <sequence>
+              <!-- Test Suite Cleanup -->
+              <message>'Finally: Replication Cleanup.'</message>
+              <try>
+                <sequence>
+                  <import machine="STAF_LOCAL_HOSTNAME"
+                    file="'%s/testcases/replication/replication_cleanup.xml' 
+                          % (TESTS_DIR)"/>
+                  <call function="'replication_cleanup'">
+                    { 'label'    : _label }
+                  </call>
+              </sequence>
+              <catch exception="'STAFException'">
+                <sequence>
+                  <message log="1" level="'fatal'">'Cleanup of test suite failed.'</message>
+                </sequence>
+              </catch>
+              <finally>
+                <call function="'testSuite_Postamble'"/>
+              </finally>
+              </try>
             </sequence>
-          </testcase>                                                                     
-
-                                                
-                                                
-          <import machine="STAF_LOCAL_HOSTNAME"
-            file="'%s/testcases/replication/replication_cleanup.xml' % (TESTS_DIR)"/>
-          <call function="'replication_cleanup'" >
-            { 'label' : 'Replication Failover' }
-          </call>
-                          
-          <call function="'testSuite_Postamble'"/>
-                  
-        </sequence>
-
+          </finally>
+ 
+        </try>
       </block>
-    
     </sequence>
-
   </function>
-
 </stax>

--
Gitblit v1.10.0