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 DifferentMtimes: 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 // Create Keep Volumes
187 KeepVM = MakeTestVolumeManager(2)
191 vols := KeepVM.AllWritable()
192 if testData.CreateData {
193 vols[0].Put(testData.Locator1, testData.Block1)
194 vols[0].Put(testData.Locator1+".meta", []byte("metadata"))
196 if testData.CreateInVolume1 {
197 vols[0].Put(testData.Locator2, testData.Block2)
198 vols[0].Put(testData.Locator2+".meta", []byte("metadata"))
200 vols[1].Put(testData.Locator2, testData.Block2)
201 vols[1].Put(testData.Locator2+".meta", []byte("metadata"))
205 oldBlockTime := time.Now().Add(-blob_signature_ttl - time.Minute)
207 // Create TrashRequest for the test
208 trashRequest := TrashRequest{
209 Locator: testData.DeleteLocator,
210 BlockMtime: oldBlockTime.Unix(),
213 // Run trash worker and put the trashRequest on trashq
214 trashList := list.New()
215 trashList.PushBack(trashRequest)
216 trashq = NewWorkQueue()
219 if !testData.UseTrashLifeTime {
220 // Trash worker would not delete block if its Mtime is
221 // within trash life time. Back-date the block to
222 // allow the deletion to succeed.
223 for _, v := range vols {
224 v.(*MockVolume).Timestamps[testData.DeleteLocator] = oldBlockTime
225 if testData.DifferentMtimes {
226 oldBlockTime = oldBlockTime.Add(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 // The DifferentMtimes test puts the same locator in two
262 // different volumes, but only one copy has an Mtime matching
263 // the trash request.
264 if testData.DifferentMtimes {
266 for _, volume := range KeepVM.AllReadable() {
267 if _, err := volume.Get(testData.Locator1); err == nil {
268 locatorFoundIn = locatorFoundIn + 1
271 if locatorFoundIn != 1 {
272 t.Errorf("Found %d copies of %s, expected 1", locatorFoundIn, testData.Locator1)