From 0e80b5fe638b159e03475d2c793f9c45e36729ec Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Wed, 26 May 2021 16:09:23 +0100 Subject: [PATCH] tests: Add test for upload of the same object inlined and not inlined (#12374) Upload an object smaller than small file threshold and upload another file bigger than small file threshold and tries to read it. --- cmd/erasure-object_test.go | 71 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/cmd/erasure-object_test.go b/cmd/erasure-object_test.go index 8b64ea067..97c26bdba 100644 --- a/cmd/erasure-object_test.go +++ b/cmd/erasure-object_test.go @@ -587,6 +587,77 @@ func TestPutObjectNoQuorumSmall(t *testing.T) { } } +// Test PutObject twice, one small and another bigger +// than small data thresold and checks reading them again +func TestPutObjectSmallInlineData(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + const numberOfDisks = 4 + + // Create an instance of xl backend. + obj, fsDirs, err := prepareErasure(ctx, numberOfDisks) + if err != nil { + t.Fatal(err) + } + + // Cleanup backend directories. + defer obj.Shutdown(context.Background()) + defer removeRoots(fsDirs) + + bucket := "bucket" + object := "object" + + // Create "bucket" + err = obj.MakeBucketWithLocation(ctx, bucket, BucketOptions{}) + if err != nil { + t.Fatal(err) + } + + // Test: Upload a small file and read it. + smallData := []byte{'a'} + _, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader(smallData), int64(len(smallData)), "", ""), ObjectOptions{}) + if err != nil { + t.Fatal(err) + } + gr, err := obj.GetObjectNInfo(ctx, bucket, object, nil, nil, readLock, ObjectOptions{}) + if err != nil { + t.Fatalf("Expected GetObject to succeed, but failed with %v", err) + } + output := bytes.NewBuffer([]byte{}) + _, err = io.Copy(output, gr) + if err != nil { + t.Fatalf("Expected GetObject reading data to succeed, but failed with %v", err) + } + gr.Close() + if !bytes.Equal(output.Bytes(), smallData) { + t.Fatalf("Corrupted data is found") + } + + // Test: Upload a file bigger than the small file threshold + // under the same bucket & key name and try to read it again. + + output.Reset() + bigData := bytes.Repeat([]byte{'b'}, smallFileThreshold*numberOfDisks/2) + + _, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader(bigData), int64(len(bigData)), "", ""), ObjectOptions{}) + if err != nil { + t.Fatal(err) + } + gr, err = obj.GetObjectNInfo(ctx, bucket, object, nil, nil, readLock, ObjectOptions{}) + if err != nil { + t.Fatalf("Expected GetObject to succeed, but failed with %v", err) + } + _, err = io.Copy(output, gr) + if err != nil { + t.Fatalf("Expected GetObject reading data to succeed, but failed with %v", err) + } + gr.Close() + if !bytes.Equal(output.Bytes(), bigData) { + t.Fatalf("Corrupted data found") + } +} + func TestObjectQuorumFromMeta(t *testing.T) { ExecObjectLayerTestWithDirs(t, testObjectQuorumFromMeta) }