9 type TrashWorkerTestData struct {
30 /* Delete block that does not exist in any of the keep volumes.
33 func TestTrashWorkerIntegration_GetNonExistingLocator(t *testing.T) {
35 testData := TrashWorkerTestData{
36 Locator1: "5d41402abc4b2a76b9719d911017c592",
37 Block1: []byte("hello"),
39 Locator2: "5d41402abc4b2a76b9719d911017c592",
40 Block2: []byte("hello"),
44 DeleteLocator: "5d41402abc4b2a76b9719d911017c592",
46 ExpectLocator1: false,
47 ExpectLocator2: false,
49 performTrashWorkerTest(testData, t)
52 /* Delete a block that exists on volume 1 of the keep servers.
53 Expect the second locator in volume 2 to be unaffected.
55 func TestTrashWorkerIntegration_LocatorInVolume1(t *testing.T) {
57 testData := TrashWorkerTestData{
61 Locator2: TEST_HASH_2,
66 DeleteLocator: TEST_HASH, // first locator
68 ExpectLocator1: false,
71 performTrashWorkerTest(testData, t)
74 /* Delete a block that exists on volume 2 of the keep servers.
75 Expect the first locator in volume 1 to be unaffected.
77 func TestTrashWorkerIntegration_LocatorInVolume2(t *testing.T) {
79 testData := TrashWorkerTestData{
83 Locator2: TEST_HASH_2,
88 DeleteLocator: TEST_HASH_2, // locator 2
91 ExpectLocator2: false,
93 performTrashWorkerTest(testData, t)
96 /* Delete a block with matching mtime for locator in both volumes.
97 Expect locator to be deleted from both volumes.
99 func TestTrashWorkerIntegration_LocatorInBothVolumes(t *testing.T) {
101 testData := TrashWorkerTestData{
110 DeleteLocator: TEST_HASH,
112 ExpectLocator1: false,
113 ExpectLocator2: false,
115 performTrashWorkerTest(testData, t)
118 /* Same locator with different Mtimes exists in both volumes.
119 Delete the second and expect the first to be still around.
121 func TestTrashWorkerIntegration_MtimeMatchesForLocator1ButNotForLocator2(t *testing.T) {
123 testData := TrashWorkerTestData{
131 DifferentMtimes: true,
133 DeleteLocator: TEST_HASH,
135 ExpectLocator1: true,
136 ExpectLocator2: false,
138 performTrashWorkerTest(testData, t)
141 /* Two different locators in volume 1.
143 Expect the other unaffected.
145 func TestTrashWorkerIntegration_TwoDifferentLocatorsInVolume1(t *testing.T) {
147 testData := TrashWorkerTestData{
151 Locator2: TEST_HASH_2,
152 Block2: TEST_BLOCK_2,
155 CreateInVolume1: true,
157 DeleteLocator: TEST_HASH, // locator 1
159 ExpectLocator1: false,
160 ExpectLocator2: true,
162 performTrashWorkerTest(testData, t)
165 /* Allow default Trash Life time to be used. Thus, the newly created block
166 will not be deleted becuase its Mtime is within the trash life time.
168 func TestTrashWorkerIntegration_SameLocatorInTwoVolumesWithDefaultTrashLifeTime(t *testing.T) {
170 testData := TrashWorkerTestData{
174 Locator2: TEST_HASH_2,
175 Block2: TEST_BLOCK_2,
178 CreateInVolume1: true,
180 UseTrashLifeTime: true,
182 DeleteLocator: TEST_HASH, // locator 1
184 // Since trash life time is in effect, block won't be deleted.
185 ExpectLocator1: true,
186 ExpectLocator2: true,
188 performTrashWorkerTest(testData, t)
191 /* Delete a block with matching mtime for locator in both volumes, but never_delete is true,
192 so block won't be deleted.
194 func TestTrashWorkerIntegration_NeverDelete(t *testing.T) {
196 testData := TrashWorkerTestData{
205 DeleteLocator: TEST_HASH,
207 ExpectLocator1: true,
208 ExpectLocator2: true,
210 performTrashWorkerTest(testData, t)
213 /* Perform the test */
214 func performTrashWorkerTest(testData TrashWorkerTestData, t *testing.T) {
215 // Create Keep Volumes
216 KeepVM = MakeTestVolumeManager(2)
220 vols := KeepVM.AllWritable()
221 if testData.CreateData {
222 vols[0].Put(testData.Locator1, testData.Block1)
223 vols[0].Put(testData.Locator1+".meta", []byte("metadata"))
225 if testData.CreateInVolume1 {
226 vols[0].Put(testData.Locator2, testData.Block2)
227 vols[0].Put(testData.Locator2+".meta", []byte("metadata"))
229 vols[1].Put(testData.Locator2, testData.Block2)
230 vols[1].Put(testData.Locator2+".meta", []byte("metadata"))
234 oldBlockTime := time.Now().Add(-blob_signature_ttl - time.Minute)
236 // Create TrashRequest for the test
237 trashRequest := TrashRequest{
238 Locator: testData.DeleteLocator,
239 BlockMtime: oldBlockTime.Unix(),
242 // Run trash worker and put the trashRequest on trashq
243 trashList := list.New()
244 trashList.PushBack(trashRequest)
245 trashq = NewWorkQueue()
248 if !testData.UseTrashLifeTime {
249 // Trash worker would not delete block if its Mtime is
250 // within trash life time. Back-date the block to
251 // allow the deletion to succeed.
252 for _, v := range vols {
253 v.(*MockVolume).Timestamps[testData.DeleteLocator] = oldBlockTime
254 if testData.DifferentMtimes {
255 oldBlockTime = oldBlockTime.Add(time.Second)
259 go RunTrashWorker(trashq)
261 trashq.ReplaceQueue(trashList)
262 time.Sleep(10 * time.Millisecond) // give a moment to finish processing the list
264 // Verify Locator1 to be un/deleted as expected
265 data, _ := GetBlock(testData.Locator1, false)
266 if testData.ExpectLocator1 {
268 t.Errorf("Expected Locator1 to be still present: %s", testData.Locator1)
272 t.Errorf("Expected Locator1 to be deleted: %s", testData.Locator1)
276 // Verify Locator2 to be un/deleted as expected
277 if testData.Locator1 != testData.Locator2 {
278 data, _ = GetBlock(testData.Locator2, false)
279 if testData.ExpectLocator2 {
281 t.Errorf("Expected Locator2 to be still present: %s", testData.Locator2)
285 t.Errorf("Expected Locator2 to be deleted: %s", testData.Locator2)
290 // The DifferentMtimes test puts the same locator in two
291 // different volumes, but only one copy has an Mtime matching
292 // the trash request.
293 if testData.DifferentMtimes {
295 for _, volume := range KeepVM.AllReadable() {
296 if _, err := volume.Get(testData.Locator1); err == nil {
297 locatorFoundIn = locatorFoundIn + 1
300 if locatorFoundIn != 1 {
301 t.Errorf("Found %d copies of %s, expected 1", locatorFoundIn, testData.Locator1)