View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *  http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.directory.server.core.integ;
20  
21  
22  /**
23   * Different modes of conducting core tests.
24   *
25   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
26   * @version $Rev$, $Date$
27   */
28  public enum SetupMode
29  {
30      /*
31  
32        MATRIX FOR MODE ACTIONS BASED ON SERVER STATE
33      
34                  | NOSERVICE | PRISTINE  | RESTART  | ROLLBACK | CUMULATIVE
35                  +===========+===========+==========+==========+===========
36                  |           |           |          |          |
37         RUNNING  |  NOTHING  | SHUTDOWN  | SHUTDOWN |  REVERT  |  NOTHING
38         STOPPED  |  NOTHING  | CLEANUP   | STARTUP  |  CLEANUP |  RESTART
39         MISSING  |  NOTHING  | CREATE    | CREATE   |  CREATE  |  CREATE
40  
41      */
42  
43  
44      /**
45       * If a service is running this mode will shutdown the service, destroy
46       * it's working directory, null it out and start all over again with a
47       * new service object to start it up fresh.  If no service is running,
48       * yet a valid handle to a stopped service exists, this handle is used
49       * to destroy the working directory then the handle is nulled out.
50       * Whether or not a valid service exists a new one is created, and
51       * started up. 
52       */
53      PRISTINE( 0, "PRISTINE: Fresh test with full working directory cleanout." ),
54      /**
55       * If a service is running this mode will shutdown the service, WITHOUT
56       * destroying it's working directory, so changes made in tests are or
57       * should be persistant. The same service object is restarted without
58       * creating a new one.  If the service exists yet is found to have been
59       * shutdown it is restarted.  If no service is available, one is created
60       * and started up.
61       */
62      RESTART( 1, "RESTART: Working directories are not cleaned out but the core is restarted." ),
63      /**
64       * If a service is running this mode will NOT shutdown the service,
65       * instead the service's state will be reverted to it's previous state
66       * before the last test which operated on it.  So changes are not
67       * persisted across tests.  If the service exists yet has been shutdown
68       * the working directory is cleaned out and the service is started up.
69       * We must destroy working directories since reverts are not possible
70       * across shutdowns at this point in time (change log is not persistent).
71       */
72      ROLLBACK( 2, "ROLLBACK: The service is not stopped, it's state is restored to the original startup state." ),
73      /**
74       * If a service is running it is used as is.  Changes across tests have
75       * no isolation.  If the service has been stopped it is simply restarted.
76       * If the service does not exists it is created then started.  There is
77       * no attempt to destroy existing working directories if any at all exist.
78       */
79      CUMULATIVE( 3, "CUMULATIVE: Nothing is done to the service between tests so changes accumulate." ),
80      /**
81       * Does nothing at all.  Does not care if service is running or if it
82       * exists.  This is the default.  Really useful with suites which you
83       * may not want to do anything with.  Otherwise for all other modes a
84       * suite will start up a server before all runs and shut it down after
85       * all runs.
86       */
87      NOSERVICE( 4, "NOSERVICE: No service is required at all." );
88  
89      public static final int PRISTINE_ORDINAL = 0;
90      public static final int RESTART_ORDINAL = 1;
91      public static final int ROLLBACK_ORDINAL = 2;
92      public static final int CUMULATIVE_ORDINAL = 3;
93      public static final int NOSERVICE_ORDINAL = 4;
94  
95  
96      public final int ordinal;
97      public final String description;
98  
99  
100     private SetupMode( int ordinal, String description )
101     {
102         this.ordinal = ordinal;
103         this.description = description;
104     }
105 
106 
107     public boolean isStartedDirtyTestable()
108     {
109         switch( ordinal )
110         {
111             case( PRISTINE_ORDINAL ):
112                 return false;
113             case( ROLLBACK_ORDINAL ):
114                 return false;
115             case( NOSERVICE_ORDINAL ):
116                 return true;
117             case( RESTART_ORDINAL ):
118                 return true;
119             case( CUMULATIVE_ORDINAL ):
120                 return true;
121             default:
122                 throw new IllegalStateException( "Unidentified ordinal value: " + ordinal );
123         }
124     }
125 }