9 type TrashWorkerTestData struct {
30 /* Delete block that does not exist in any of the keep volumes.
33 func TestTrashWorkerIntegration_GetNonExistingLocator(t *testing.T) {
34 testData := TrashWorkerTestData{
35 Locator1: "5d41402abc4b2a76b9719d911017c592",
36 Block1: []byte("hello"),
38 Locator2: "5d41402abc4b2a76b9719d911017c592",
39 Block2: []byte("hello"),
43 DeleteLocator: "5d41402abc4b2a76b9719d911017c592",
45 ExpectLocator1: false,
46 ExpectLocator2: false,
48 performTrashWorkerTest(testData, t)
51 /* Delete a block that exists on volume 1 of the keep servers.
52 Expect the second locator in volume 2 to be unaffected.
54 func TestTrashWorkerIntegration_LocatorInVolume1(t *testing.T) {
55 testData := TrashWorkerTestData{
59 Locator2: TEST_HASH_2,
64 DeleteLocator: TEST_HASH, // first locator
66 ExpectLocator1: false,
69 performTrashWorkerTest(testData, t)
72 /* Delete a block that exists on volume 2 of the keep servers.
73 Expect the first locator in volume 1 to be unaffected.
75 func TestTrashWorkerIntegration_LocatorInVolume2(t *testing.T) {
76 testData := TrashWorkerTestData{
80 Locator2: TEST_HASH_2,
85 DeleteLocator: TEST_HASH_2, // locator 2
88 ExpectLocator2: false,
90 performTrashWorkerTest(testData, t)
93 /* Delete a block with matching mtime for locator in both volumes.
94 Expect locator to be deleted from both volumes.
96 func TestTrashWorkerIntegration_LocatorInBothVolumes(t *testing.T) {
97 testData := TrashWorkerTestData{
106 DeleteLocator: TEST_HASH,
108 ExpectLocator1: false,
109 ExpectLocator2: false,
111 performTrashWorkerTest(testData, t)
114 /* Same locator with different Mtimes exists in both volumes.
115 Delete the second and expect the first to be still around.
117 func TestTrashWorkerIntegration_MtimeMatchesForLocator1ButNotForLocator2(t *testing.T) {
118 testData := TrashWorkerTestData{
126 UseDelayToCreate: true,
128 DeleteLocator: TEST_HASH,
130 ExpectLocator1: true,
131 ExpectLocator2: false,
133 performTrashWorkerTest(testData, t)
136 /* Two different locators in volume 1.
138 Expect the other unaffected.
140 func TestTrashWorkerIntegration_TwoDifferentLocatorsInVolume1(t *testing.T) {
141 testData := TrashWorkerTestData{
145 Locator2: TEST_HASH_2,
146 Block2: TEST_BLOCK_2,
149 CreateInVolume1: true,
151 DeleteLocator: TEST_HASH, // locator 1
153 ExpectLocator1: false,
154 ExpectLocator2: true,
156 performTrashWorkerTest(testData, t)
159 /* Allow default Trash Life time to be used. Thus, the newly created block
160 will not be deleted becuase its Mtime is within the trash life time.
162 func TestTrashWorkerIntegration_SameLocatorInTwoVolumesWithDefaultTrashLifeTime(t *testing.T) {
163 testData := TrashWorkerTestData{
167 Locator2: TEST_HASH_2,
168 Block2: TEST_BLOCK_2,
171 CreateInVolume1: true,
173 UseTrashLifeTime: true,
175 DeleteLocator: TEST_HASH, // locator 1
177 // Since trash life time is in effect, block won't be deleted.
178 ExpectLocator1: true,
179 ExpectLocator2: true,
181 performTrashWorkerTest(testData, t)
184 /* Perform the test */
185 func performTrashWorkerTest(testData TrashWorkerTestData, t *testing.T) {
186 actual_permission_ttl := permission_ttl
188 // Create Keep Volumes
189 KeepVM = MakeTestVolumeManager(2)
192 vols := KeepVM.Volumes()
193 if testData.CreateData {
194 vols[0].Put(testData.Locator1, testData.Block1)
195 vols[0].Put(testData.Locator1+".meta", []byte("metadata"))
197 // One of the tests deletes a locator with different Mtimes in two different volumes
198 if testData.UseDelayToCreate {
199 time.Sleep(1 * time.Second)
202 if testData.CreateInVolume1 {
203 vols[0].Put(testData.Locator2, testData.Block2)
204 vols[0].Put(testData.Locator2+".meta", []byte("metadata"))
206 vols[1].Put(testData.Locator2, testData.Block2)
207 vols[1].Put(testData.Locator2+".meta", []byte("metadata"))
211 // Create TrashRequest for the test
212 trashRequest := TrashRequest{
213 Locator: testData.DeleteLocator,
214 BlockMtime: time.Now().Unix(),
217 // delay by permission_ttl to allow deletes to work
218 time.Sleep(1 * time.Second)
220 // Run trash worker and put the trashRequest on trashq
221 trashList := list.New()
222 trashList.PushBack(trashRequest)
223 trashq = NewWorkQueue()
225 // Trash worker would not delete block if its Mtime is within trash life time.
226 // Hence, we will have to bypass it to allow the deletion to succeed.
227 if !testData.UseTrashLifeTime {
228 permission_ttl = time.Duration(1) * time.Second
230 go RunTrashWorker(trashq)
232 trashq.ReplaceQueue(trashList)
233 time.Sleep(10 * time.Millisecond) // give a moment to finish processing the list
235 // Verify Locator1 to be un/deleted as expected
236 data, _ := GetBlock(testData.Locator1, false)
237 if testData.ExpectLocator1 {
239 t.Errorf("Expected Locator1 to be still present: %s", testData.Locator1)
243 t.Errorf("Expected Locator1 to be deleted: %s", testData.Locator1)
247 // Verify Locator2 to be un/deleted as expected
248 if testData.Locator1 != testData.Locator2 {
249 data, _ = GetBlock(testData.Locator2, false)
250 if testData.ExpectLocator2 {
252 t.Errorf("Expected Locator2 to be still present: %s", testData.Locator2)
256 t.Errorf("Expected Locator2 to be deleted: %s", testData.Locator2)
261 // One test used the same locator in two different volumes but with different Mtime values
262 // Hence let's verify that only one volume has it and the other is deleted
263 if (testData.ExpectLocator1) &&
264 (testData.Locator1 == testData.Locator2) {
266 for _, volume := range KeepVM.Volumes() {
267 if _, err := volume.Get(testData.Locator1); err == nil {
268 locatorFoundIn = locatorFoundIn + 1
271 if locatorFoundIn != 1 {
272 t.Errorf("Expected locator to be found in only one volume after deleting. But found: %s", locatorFoundIn)
277 permission_ttl = actual_permission_ttl