View Javadoc

1   package org.apache.continuum.purge.executor;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  /**
23   * @author Maria Catherine Tan
24   */
25  public class DaysOldDirectoryPurgeExecutorTest
26      extends AbstractPurgeExecutorTest
27  {
28      protected void setUp()
29          throws Exception
30      {
31          super.setUp();
32  
33          purgeReleasesDirTask = getDaysOldReleasesDirPurgeTask();
34  
35          purgeBuildOutputDirTask = getDaysOldBuildOutputDirPurgeTask();
36      }
37  
38      public void testReleasesDirPurgingByLastModified()
39          throws Exception
40      {
41          populateReleasesDirectory();
42  
43          String dirPath = getReleasesDirectoryLocation().getAbsolutePath();
44  
45          setLastModified( dirPath, 1179382029, true );
46          setLastModified( dirPath + "/releases-1234567809", 1023453892, false );
47  
48          purgeExecutor.executeTask( purgeReleasesDirTask );
49  
50          assertDeleted( dirPath + "/releases-1234567809" );
51  
52          assertExists( dirPath + "/1" );
53          assertExists( dirPath + "/releases-1234567890" );
54          assertExists( dirPath + "/releases-4234729018" );
55      }
56  
57      public void testReleasesDirPurgingByOrderOfDeletion()
58          throws Exception
59      {
60          populateReleasesDirectory();
61  
62          String dirPath = getReleasesDirectoryLocation().getAbsolutePath();
63  
64          setLastModified( dirPath + "/releases-4234729018", new Long( "1234567809" ), false );
65          setLastModified( dirPath + "/releases-1234567809", new Long( "4234729018" ), false );
66          setLastModified( dirPath + "/releases-1234567890", new Long( "2234567890" ), false );
67  
68          purgeExecutor.executeTask( purgeReleasesDirTask );
69  
70          assertDeleted( dirPath + "/releases-4234729018" );
71  
72          assertExists( dirPath + "/1" );
73          assertExists( dirPath + "/releases-1234567890" );
74          assertExists( dirPath + "/releases-1234567809" );
75      }
76  
77      public void testBuildOutputPurgingByLastModified()
78          throws Exception
79      {
80          populateBuildOutputDirectory();
81  
82          String dirPath = getBuildOutputDirectoryLocation().getAbsolutePath();
83  
84          setLastModified( dirPath, 1179382029, true );
85          setLastModified( dirPath + "/1/1", 1023453892, false );
86          setLastModified( dirPath + "/1/1.log.txt", 1023453892, false );
87          setLastModified( dirPath + "/2/4", 1023453892, false );
88          setLastModified( dirPath + "/2/4.log.txt", 1023453892, false );
89  
90          purgeExecutor.executeTask( purgeBuildOutputDirTask );
91  
92          assertDeleted( dirPath + "/1/1" );
93          assertDeleted( dirPath + "/1/1.log.txt" );
94  
95          assertExists( dirPath + "/1/3" );
96          assertExists( dirPath + "/1/3.log.txt" );
97          assertExists( dirPath + "/1/6" );
98          assertExists( dirPath + "/1/6.log.txt" );
99  
100         assertDeleted( dirPath + "/2/4" );
101         assertDeleted( dirPath + "/2/4.log.txt" );
102 
103         assertExists( dirPath + "/2/7" );
104         assertExists( dirPath + "/2/7.log.txt" );
105         assertExists( dirPath + "/2/9" );
106         assertExists( dirPath + "/2/9.log.txt" );
107     }
108 
109     public void testBuildOutputPurgingByOrderOfDeletion()
110         throws Exception
111     {
112         populateBuildOutputDirectory();
113 
114         String dirPath = getBuildOutputDirectoryLocation().getAbsolutePath();
115 
116         setLastModified( dirPath + "/1/6", new Long( "1234567809" ), false );
117         setLastModified( dirPath + "/1/6.log.txt", new Long( "1234567809" ), false );
118         setLastModified( dirPath + "/1/1", new Long( "4234729018" ), false );
119         setLastModified( dirPath + "/1/1.log.txt", new Long( "4234729018" ), false );
120         setLastModified( dirPath + "/1/3", new Long( "2234567890" ), false );
121         setLastModified( dirPath + "/1/3.log.txt", new Long( "2234567890" ), false );
122 
123         setLastModified( dirPath + "/2/7", new Long( "1234567809" ), false );
124         setLastModified( dirPath + "/2/7.log.txt", new Long( "1234567809" ), false );
125         setLastModified( dirPath + "/2/4", new Long( "4234729018" ), false );
126         setLastModified( dirPath + "/2/4.log.txt", new Long( "4234729018" ), false );
127         setLastModified( dirPath + "/2/9", new Long( "2234567890" ), false );
128         setLastModified( dirPath + "/2/9.log.txt", new Long( "2234567890" ), false );
129 
130         purgeExecutor.executeTask( purgeBuildOutputDirTask );
131 
132         assertDeleted( dirPath + "/1/6" );
133         assertDeleted( dirPath + "/1/6.log.txt" );
134 
135         assertExists( dirPath + "/1/3" );
136         assertExists( dirPath + "/1/3.log.txt" );
137         assertExists( dirPath + "/1/1" );
138         assertExists( dirPath + "/1/1.log.txt" );
139 
140         assertDeleted( dirPath + "/2/7" );
141         assertDeleted( dirPath + "/2/7.log.txt" );
142 
143         assertExists( dirPath + "/2/4" );
144         assertExists( dirPath + "/2/4.log.txt" );
145         assertExists( dirPath + "/2/9" );
146         assertExists( dirPath + "/2/9.log.txt" );
147     }
148 }