[ARVADOS] created: 5a7b7ea65edaf40f5d9c17adc2184b0a96f05a2d

git at public.curoverse.com git at public.curoverse.com
Tue Jan 26 23:32:04 EST 2016


        at  5a7b7ea65edaf40f5d9c17adc2184b0a96f05a2d (commit)


commit 5a7b7ea65edaf40f5d9c17adc2184b0a96f05a2d
Author: radhika <radhika at curoverse.com>
Date:   Tue Jan 26 23:31:27 2016 -0500

    8178: add generic volume tests for trash / untrash interface.

diff --git a/services/keepstore/volume_generic_test.go b/services/keepstore/volume_generic_test.go
index e168940..71dfa24 100644
--- a/services/keepstore/volume_generic_test.go
+++ b/services/keepstore/volume_generic_test.go
@@ -76,6 +76,10 @@ func DoGenericVolumeTests(t TB, factory TestableVolumeFactory) {
 	testPutConcurrent(t, factory)
 
 	testPutFullBlock(t, factory)
+
+	testTrashUntrashNewBlock(t, factory)
+	testTrashUntrashOldBlock(t, factory)
+	testTrashUntrashWithNonZeroTrashLifetime(t, factory)
 }
 
 // Put a test block, get it and verify content
@@ -696,3 +700,148 @@ func testPutFullBlock(t TB, factory TestableVolumeFactory) {
 		t.Error("rdata != wdata")
 	}
 }
+
+// With acceptable trashLifetime configuration, perform:
+// Trash newer block - does not actually delete the new block
+// Untrash - which raises ErrNotImplemented
+// Get - which fails on the trashed locator
+func testTrashUntrashNewBlock(t TB, factory TestableVolumeFactory) {
+	v := factory(t)
+	defer v.Teardown()
+
+	v.PutRaw(TestHash, TestBlock)
+	buf, err := v.Get(TestHash)
+	if err != nil {
+		t.Errorf("got err %v, expected nil", err)
+	}
+	bufs.Put(buf)
+
+	// Trash
+	err = v.Trash(TestHash)
+	if v.Writable() == false {
+		if err != MethodDisabledError {
+			t.Errorf("Expected MethodDisabledError during Trash from a read-only volume")
+		}
+	} else if err != nil {
+		t.Errorf("Error during Trash %v", err.Error())
+	}
+
+	// Untrash
+	err = v.Untrash(TestHash)
+	if err != ErrNotImplemented {
+		t.Errorf("Expected ErrNotImplemented during Untrash")
+	}
+
+	// Get
+	buf, err = v.Get(TestHash)
+	if err != nil {
+		t.Errorf("Error during Get: %v", err.Error())
+	} else {
+		if bytes.Compare(buf, TestBlock) != 0 {
+			t.Errorf("Got data %+q, expected %+q", buf, TestBlock)
+		}
+		bufs.Put(buf)
+	}
+}
+
+// With acceptable trashLifetime configuration, perform:
+// Trash an old block - which works and hence deletes the locator
+// Untrash - which raises ErrNotImplemented
+// Get - which fails on the trashed locator
+func testTrashUntrashOldBlock(t TB, factory TestableVolumeFactory) {
+	v := factory(t)
+	defer v.Teardown()
+
+	v.PutRaw(TestHash, TestBlock)
+	blobSignatureTTL = 300 * time.Second
+	v.TouchWithDate(TestHash, time.Now().Add(-2*blobSignatureTTL))
+
+	buf, err := v.Get(TestHash)
+	if err != nil {
+		t.Errorf("got err %v, expected nil", err)
+	}
+	bufs.Put(buf)
+
+	// Trash
+	err = v.Trash(TestHash)
+	if v.Writable() == false {
+		if err != MethodDisabledError {
+			t.Errorf("Expected MethodDisabledError during Trash from a read-only volume")
+		}
+	} else if err != nil {
+		t.Errorf("Error during Trash %v", err.Error())
+	}
+
+	// Untrash
+	err = v.Untrash(TestHash)
+	if err != ErrNotImplemented {
+		t.Errorf("Expected ErrNotImplemented during Untrash")
+	}
+
+	// Get
+	buf, err = v.Get(TestHash)
+	if v.Writable() {
+		if err == nil || !os.IsNotExist(err) {
+			t.Errorf("os.IsNotExist(%v) should have been true", err)
+		}
+		return
+	}
+	// Not writable; hence the block was not trashed
+	if err != nil {
+		t.Errorf("Error during Get: %v", err.Error())
+	} else {
+		if bytes.Compare(buf, TestBlock) != 0 {
+			t.Errorf("Got data %+q, expected %+q", buf, TestBlock)
+		}
+		bufs.Put(buf)
+	}
+}
+
+// With non-zero trashLifetime configuration, perform:
+// Trash - which raises ErrNotImplemented and hence does not Trash
+// Untrash - which raises ErrNotImplemented
+// Get - which passes since Trash did not work
+func testTrashUntrashWithNonZeroTrashLifetime(t TB, factory TestableVolumeFactory) {
+	v := factory(t)
+	defer v.Teardown()
+	defer func() {
+		trashLifetime = 0
+	}()
+
+	v.PutRaw(TestHash, TestBlock)
+	buf, err := v.Get(TestHash)
+	if err != nil {
+		t.Errorf("got err %v, expected nil", err)
+	}
+	bufs.Put(buf)
+
+	// trashLifetime == 0 is the only supported configuration
+	trashLifetime = 1000
+
+	// Trash
+	err = v.Trash(TestHash)
+	if v.Writable() == false {
+		if err != MethodDisabledError {
+			t.Errorf("Expected MethodDisabledError during Trash from a read-only volume")
+		}
+	} else if err != ErrNotImplemented {
+		t.Errorf("Expected ErrNotImplemented during Trash")
+	}
+
+	// Untrash
+	err = v.Untrash(TestHash)
+	if err != ErrNotImplemented {
+		t.Errorf("Expected ErrNotImplemented during Untrash")
+	}
+
+	// Get
+	buf, err = v.Get(TestHash)
+	if err != nil {
+		t.Errorf("Error during Get: %v", err.Error())
+	} else {
+		if bytes.Compare(buf, TestBlock) != 0 {
+			t.Errorf("Got data %+q, expected %+q", buf, TestBlock)
+		}
+		bufs.Put(buf)
+	}
+}

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list