You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
549 lines
17 KiB
549 lines
17 KiB
9 years ago
|
/*
|
||
5 years ago
|
* MinIO Cloud Storage, (C) 2016-2020 MinIO, Inc.
|
||
9 years ago
|
*
|
||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
* you may not use this file except in compliance with the License.
|
||
|
* You may obtain a copy of the License at
|
||
|
*
|
||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||
|
*
|
||
|
* Unless required by applicable law or agreed to in writing, software
|
||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
* See the License for the specific language governing permissions and
|
||
|
* limitations under the License.
|
||
|
*/
|
||
|
|
||
8 years ago
|
package cmd
|
||
9 years ago
|
|
||
|
import (
|
||
|
"bytes"
|
||
5 years ago
|
"context"
|
||
8 years ago
|
"io/ioutil"
|
||
8 years ago
|
"os"
|
||
9 years ago
|
"testing"
|
||
8 years ago
|
|
||
|
humanize "github.com/dustin/go-humanize"
|
||
5 years ago
|
"github.com/minio/minio/cmd/config/storageclass"
|
||
9 years ago
|
)
|
||
|
|
||
|
func TestRepeatPutObjectPart(t *testing.T) {
|
||
5 years ago
|
ctx, cancel := context.WithCancel(context.Background())
|
||
|
defer cancel()
|
||
|
|
||
9 years ago
|
var objLayer ObjectLayer
|
||
|
var disks []string
|
||
|
var err error
|
||
6 years ago
|
var opts ObjectOptions
|
||
9 years ago
|
|
||
5 years ago
|
objLayer, disks, err = prepareErasure16(ctx)
|
||
9 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
// cleaning up of temporary test directories
|
||
|
defer removeRoots(disks)
|
||
|
|
||
5 years ago
|
err = objLayer.MakeBucketWithLocation(ctx, "bucket1", BucketOptions{})
|
||
9 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
5 years ago
|
uploadID, err := objLayer.NewMultipartUpload(ctx, "bucket1", "mpartObj1", opts)
|
||
9 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
8 years ago
|
fiveMBBytes := bytes.Repeat([]byte("a"), 5*humanize.MiByte)
|
||
8 years ago
|
md5Hex := getMD5Hash(fiveMBBytes)
|
||
5 years ago
|
_, err = objLayer.PutObjectPart(ctx, "bucket1", "mpartObj1", uploadID, 1, mustGetPutObjReader(t, bytes.NewReader(fiveMBBytes), 5*humanize.MiByte, md5Hex, ""), opts)
|
||
9 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
// PutObjectPart should succeed even if part already exists. ref: https://github.com/minio/minio/issues/1930
|
||
5 years ago
|
_, err = objLayer.PutObjectPart(ctx, "bucket1", "mpartObj1", uploadID, 1, mustGetPutObjReader(t, bytes.NewReader(fiveMBBytes), 5*humanize.MiByte, md5Hex, ""), opts)
|
||
9 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
}
|
||
8 years ago
|
|
||
5 years ago
|
func TestErasureDeleteObjectBasic(t *testing.T) {
|
||
8 years ago
|
testCases := []struct {
|
||
|
bucket string
|
||
|
object string
|
||
|
expectedErr error
|
||
|
}{
|
||
6 years ago
|
{".test", "dir/obj", BucketNameInvalid{Bucket: ".test"}},
|
||
|
{"----", "dir/obj", BucketNameInvalid{Bucket: "----"}},
|
||
8 years ago
|
{"bucket", "", ObjectNameInvalid{Bucket: "bucket", Object: ""}},
|
||
|
{"bucket", "doesnotexist", ObjectNotFound{Bucket: "bucket", Object: "doesnotexist"}},
|
||
6 years ago
|
{"bucket", "dir/doesnotexist", ObjectNotFound{Bucket: "bucket", Object: "dir/doesnotexist"}},
|
||
|
{"bucket", "dir", ObjectNotFound{Bucket: "bucket", Object: "dir"}},
|
||
|
{"bucket", "dir/", ObjectNotFound{Bucket: "bucket", Object: "dir/"}},
|
||
|
{"bucket", "dir/obj", nil},
|
||
8 years ago
|
}
|
||
|
|
||
5 years ago
|
ctx, cancel := context.WithCancel(context.Background())
|
||
|
defer cancel()
|
||
|
|
||
8 years ago
|
// Create an instance of xl backend
|
||
5 years ago
|
xl, fsDirs, err := prepareErasure16(ctx)
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
5 years ago
|
err = xl.MakeBucketWithLocation(ctx, "bucket", BucketOptions{})
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
6 years ago
|
// Create object "dir/obj" under bucket "bucket" for Test 7 to pass
|
||
5 years ago
|
_, err = xl.PutObject(ctx, "bucket", "dir/obj", mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{})
|
||
8 years ago
|
if err != nil {
|
||
5 years ago
|
t.Fatalf("Erasure Object upload failed: <ERROR> %s", err)
|
||
8 years ago
|
}
|
||
5 years ago
|
for _, test := range testCases {
|
||
|
test := test
|
||
|
t.Run("", func(t *testing.T) {
|
||
|
_, actualErr := xl.DeleteObject(ctx, test.bucket, test.object, ObjectOptions{})
|
||
|
if test.expectedErr != nil && actualErr != test.expectedErr {
|
||
|
t.Errorf("Expected to fail with %s, but failed with %s", test.expectedErr, actualErr)
|
||
|
}
|
||
|
if test.expectedErr == nil && actualErr != nil {
|
||
|
t.Errorf("Expected to pass, but failed with %s", actualErr)
|
||
|
}
|
||
|
})
|
||
8 years ago
|
}
|
||
|
// Cleanup backend directories
|
||
|
removeRoots(fsDirs)
|
||
|
}
|
||
6 years ago
|
|
||
5 years ago
|
func TestErasureDeleteObjectsErasureSet(t *testing.T) {
|
||
5 years ago
|
ctx, cancel := context.WithCancel(context.Background())
|
||
|
defer cancel()
|
||
5 years ago
|
var objs []*erasureObjects
|
||
6 years ago
|
for i := 0; i < 32; i++ {
|
||
5 years ago
|
obj, fsDirs, err := prepareErasure(ctx, 16)
|
||
6 years ago
|
if err != nil {
|
||
5 years ago
|
t.Fatal("Unable to initialize 'Erasure' object layer.", err)
|
||
6 years ago
|
}
|
||
|
// Remove all dirs.
|
||
|
for _, dir := range fsDirs {
|
||
|
defer os.RemoveAll(dir)
|
||
|
}
|
||
5 years ago
|
z := obj.(*erasureZones)
|
||
5 years ago
|
xl := z.zones[0].sets[0]
|
||
|
objs = append(objs, xl)
|
||
6 years ago
|
}
|
||
|
|
||
5 years ago
|
erasureSets := &erasureSets{sets: objs, distributionAlgo: "CRCMOD"}
|
||
6 years ago
|
|
||
|
type testCaseType struct {
|
||
|
bucket string
|
||
|
object string
|
||
|
}
|
||
|
|
||
|
bucketName := "bucket"
|
||
|
testCases := []testCaseType{
|
||
|
{bucketName, "dir/obj1"},
|
||
|
{bucketName, "dir/obj2"},
|
||
|
{bucketName, "obj3"},
|
||
|
{bucketName, "obj_4"},
|
||
|
}
|
||
|
|
||
5 years ago
|
err := erasureSets.MakeBucketWithLocation(ctx, bucketName, BucketOptions{})
|
||
6 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
for _, testCase := range testCases {
|
||
5 years ago
|
_, err = erasureSets.PutObject(ctx, testCase.bucket, testCase.object,
|
||
6 years ago
|
mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), ObjectOptions{})
|
||
|
if err != nil {
|
||
5 years ago
|
t.Fatalf("Erasure Object upload failed: <ERROR> %s", err)
|
||
6 years ago
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
toObjectNames := func(testCases []testCaseType) []ObjectToDelete {
|
||
|
names := make([]ObjectToDelete, len(testCases))
|
||
6 years ago
|
for i := range testCases {
|
||
5 years ago
|
names[i] = ObjectToDelete{ObjectName: testCases[i].object}
|
||
6 years ago
|
}
|
||
|
return names
|
||
|
}
|
||
|
|
||
|
objectNames := toObjectNames(testCases)
|
||
5 years ago
|
_, delErrs := erasureSets.DeleteObjects(ctx, bucketName, objectNames, ObjectOptions{})
|
||
6 years ago
|
|
||
|
for i := range delErrs {
|
||
|
if delErrs[i] != nil {
|
||
|
t.Errorf("Failed to remove object `%v` with the error: `%v`", objectNames[i], delErrs[i])
|
||
|
}
|
||
|
}
|
||
|
|
||
|
for _, test := range testCases {
|
||
5 years ago
|
_, statErr := erasureSets.GetObjectInfo(ctx, test.bucket, test.object, ObjectOptions{})
|
||
6 years ago
|
switch statErr.(type) {
|
||
|
case ObjectNotFound:
|
||
|
default:
|
||
5 years ago
|
t.Fatalf("Object %s is not removed", test.bucket+SlashSeparator+test.object)
|
||
6 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
func TestErasureDeleteObjectDiskNotFound(t *testing.T) {
|
||
5 years ago
|
ctx, cancel := context.WithCancel(context.Background())
|
||
|
defer cancel()
|
||
|
|
||
8 years ago
|
// Create an instance of xl backend.
|
||
5 years ago
|
obj, fsDirs, err := prepareErasure16(ctx)
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
5 years ago
|
// Cleanup backend directories
|
||
|
defer removeRoots(fsDirs)
|
||
8 years ago
|
|
||
5 years ago
|
z := obj.(*erasureZones)
|
||
5 years ago
|
xl := z.zones[0].sets[0]
|
||
8 years ago
|
|
||
|
// Create "bucket"
|
||
5 years ago
|
err = obj.MakeBucketWithLocation(ctx, "bucket", BucketOptions{})
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
bucket := "bucket"
|
||
|
object := "object"
|
||
6 years ago
|
opts := ObjectOptions{}
|
||
8 years ago
|
// Create object "obj" under bucket "bucket".
|
||
5 years ago
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts)
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
8 years ago
|
// for a 16 disk setup, quorum is 9. To simulate disks not found yet
|
||
|
// quorum is available, we remove disks leaving quorum disks behind.
|
||
5 years ago
|
erasureDisks := xl.getDisks()
|
||
|
z.zones[0].erasureDisksMu.Lock()
|
||
5 years ago
|
xl.getDisks = func() []StorageAPI {
|
||
5 years ago
|
for i := range erasureDisks[:7] {
|
||
|
erasureDisks[i] = newNaughtyDisk(erasureDisks[i], nil, errFaultyDisk)
|
||
5 years ago
|
}
|
||
5 years ago
|
return erasureDisks
|
||
8 years ago
|
}
|
||
5 years ago
|
|
||
|
z.zones[0].erasureDisksMu.Unlock()
|
||
|
_, err = obj.DeleteObject(ctx, bucket, object, ObjectOptions{})
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
// Create "obj" under "bucket".
|
||
5 years ago
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts)
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
// Remove one more disk to 'lose' quorum, by setting it to nil.
|
||
5 years ago
|
erasureDisks = xl.getDisks()
|
||
|
z.zones[0].erasureDisksMu.Lock()
|
||
5 years ago
|
xl.getDisks = func() []StorageAPI {
|
||
5 years ago
|
erasureDisks[7] = nil
|
||
|
erasureDisks[8] = nil
|
||
|
return erasureDisks
|
||
5 years ago
|
}
|
||
5 years ago
|
|
||
|
z.zones[0].erasureDisksMu.Unlock()
|
||
|
_, err = obj.DeleteObject(ctx, bucket, object, ObjectOptions{})
|
||
|
// since majority of disks are not available, metaquorum is not achieved and hence errErasureWriteQuorum error
|
||
|
if err != toObjectErr(errErasureWriteQuorum, bucket, object) {
|
||
|
t.Errorf("Expected deleteObject to fail with %v, but failed with %v", toObjectErr(errErasureWriteQuorum, bucket, object), err)
|
||
8 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func TestGetObjectNoQuorum(t *testing.T) {
|
||
5 years ago
|
ctx, cancel := context.WithCancel(context.Background())
|
||
|
defer cancel()
|
||
|
|
||
8 years ago
|
// Create an instance of xl backend.
|
||
5 years ago
|
obj, fsDirs, err := prepareErasure16(ctx)
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
5 years ago
|
// Cleanup backend directories.
|
||
|
defer removeRoots(fsDirs)
|
||
8 years ago
|
|
||
5 years ago
|
z := obj.(*erasureZones)
|
||
5 years ago
|
xl := z.zones[0].sets[0]
|
||
8 years ago
|
|
||
|
// Create "bucket"
|
||
5 years ago
|
err = obj.MakeBucketWithLocation(ctx, "bucket", BucketOptions{})
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
bucket := "bucket"
|
||
|
object := "object"
|
||
6 years ago
|
opts := ObjectOptions{}
|
||
8 years ago
|
// Create "object" under "bucket".
|
||
5 years ago
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts)
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
7 years ago
|
|
||
8 years ago
|
// Make 9 disks offline, which leaves less than quorum number of disks
|
||
5 years ago
|
// in a 16 disk Erasure setup. The original disks are 'replaced' with
|
||
8 years ago
|
// naughtyDisks that fail after 'f' successful StorageAPI method
|
||
8 years ago
|
// invocations, where f - [0,2)
|
||
|
for f := 0; f < 2; f++ {
|
||
8 years ago
|
diskErrors := make(map[int]error)
|
||
|
for i := 0; i <= f; i++ {
|
||
|
diskErrors[i] = nil
|
||
|
}
|
||
5 years ago
|
erasureDisks := xl.getDisks()
|
||
|
for i := range erasureDisks[:9] {
|
||
|
switch diskType := erasureDisks[i].(type) {
|
||
8 years ago
|
case *naughtyDisk:
|
||
5 years ago
|
erasureDisks[i] = newNaughtyDisk(diskType.disk, diskErrors, errFaultyDisk)
|
||
7 years ago
|
default:
|
||
5 years ago
|
erasureDisks[i] = newNaughtyDisk(erasureDisks[i], diskErrors, errFaultyDisk)
|
||
8 years ago
|
}
|
||
|
}
|
||
5 years ago
|
z.zones[0].erasureDisksMu.Lock()
|
||
5 years ago
|
xl.getDisks = func() []StorageAPI {
|
||
5 years ago
|
return erasureDisks
|
||
5 years ago
|
}
|
||
5 years ago
|
z.zones[0].erasureDisksMu.Unlock()
|
||
8 years ago
|
// Fetch object from store.
|
||
5 years ago
|
err = xl.GetObject(ctx, bucket, object, 0, int64(len("abcd")), ioutil.Discard, "", opts)
|
||
5 years ago
|
if err != toObjectErr(errErasureReadQuorum, bucket, object) {
|
||
|
t.Errorf("Expected putObject to fail with %v, but failed with %v", toObjectErr(errErasureWriteQuorum, bucket, object), err)
|
||
8 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestPutObjectNoQuorum(t *testing.T) {
|
||
5 years ago
|
ctx, cancel := context.WithCancel(context.Background())
|
||
|
defer cancel()
|
||
|
|
||
8 years ago
|
// Create an instance of xl backend.
|
||
5 years ago
|
obj, fsDirs, err := prepareErasure16(ctx)
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
5 years ago
|
// Cleanup backend directories.
|
||
|
defer removeRoots(fsDirs)
|
||
|
|
||
5 years ago
|
z := obj.(*erasureZones)
|
||
5 years ago
|
xl := z.zones[0].sets[0]
|
||
8 years ago
|
|
||
|
// Create "bucket"
|
||
5 years ago
|
err = obj.MakeBucketWithLocation(ctx, "bucket", BucketOptions{})
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
bucket := "bucket"
|
||
|
object := "object"
|
||
6 years ago
|
opts := ObjectOptions{}
|
||
8 years ago
|
// Create "object" under "bucket".
|
||
5 years ago
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts)
|
||
8 years ago
|
if err != nil {
|
||
|
t.Fatal(err)
|
||
|
}
|
||
|
|
||
|
// Make 9 disks offline, which leaves less than quorum number of disks
|
||
5 years ago
|
// in a 16 disk Erasure setup. The original disks are 'replaced' with
|
||
8 years ago
|
// naughtyDisks that fail after 'f' successful StorageAPI method
|
||
8 years ago
|
// invocations, where f - [0,3)
|
||
|
for f := 0; f < 3; f++ {
|
||
8 years ago
|
diskErrors := make(map[int]error)
|
||
|
for i := 0; i <= f; i++ {
|
||
|
diskErrors[i] = nil
|
||
|
}
|
||
5 years ago
|
erasureDisks := xl.getDisks()
|
||
|
for i := range erasureDisks[:9] {
|
||
|
switch diskType := erasureDisks[i].(type) {
|
||
8 years ago
|
case *naughtyDisk:
|
||
5 years ago
|
erasureDisks[i] = newNaughtyDisk(diskType.disk, diskErrors, errFaultyDisk)
|
||
7 years ago
|
default:
|
||
5 years ago
|
erasureDisks[i] = newNaughtyDisk(erasureDisks[i], diskErrors, errFaultyDisk)
|
||
8 years ago
|
}
|
||
|
}
|
||
5 years ago
|
z.zones[0].erasureDisksMu.Lock()
|
||
5 years ago
|
xl.getDisks = func() []StorageAPI {
|
||
5 years ago
|
return erasureDisks
|
||
5 years ago
|
}
|
||
5 years ago
|
z.zones[0].erasureDisksMu.Unlock()
|
||
8 years ago
|
// Upload new content to same object "object"
|
||
5 years ago
|
_, err = obj.PutObject(ctx, bucket, object, mustGetPutObjReader(t, bytes.NewReader([]byte("abcd")), int64(len("abcd")), "", ""), opts)
|
||
5 years ago
|
if err != toObjectErr(errErasureWriteQuorum, bucket, object) {
|
||
|
t.Errorf("Expected putObject to fail with %v, but failed with %v", toObjectErr(errErasureWriteQuorum, bucket, object), err)
|
||
8 years ago
|
}
|
||
|
}
|
||
|
}
|
||
8 years ago
|
|
||
5 years ago
|
func TestObjectQuorumFromMeta(t *testing.T) {
|
||
|
ExecObjectLayerTestWithDirs(t, testObjectQuorumFromMeta)
|
||
|
}
|
||
|
|
||
|
func testObjectQuorumFromMeta(obj ObjectLayer, instanceType string, dirs []string, t TestErrHandler) {
|
||
5 years ago
|
restoreGlobalStorageClass := globalStorageClass
|
||
|
defer func() {
|
||
|
globalStorageClass = restoreGlobalStorageClass
|
||
|
}()
|
||
|
|
||
5 years ago
|
bucket := getRandomBucketName()
|
||
|
|
||
|
var opts ObjectOptions
|
||
|
// make data with more than one part
|
||
|
partCount := 3
|
||
5 years ago
|
data := bytes.Repeat([]byte("a"), 6*1024*1024*partCount)
|
||
|
|
||
5 years ago
|
z := obj.(*erasureZones)
|
||
5 years ago
|
xl := z.zones[0].sets[0]
|
||
5 years ago
|
erasureDisks := xl.getDisks()
|
||
|
|
||
|
ctx, cancel := context.WithCancel(GlobalContext)
|
||
|
defer cancel()
|
||
5 years ago
|
|
||
5 years ago
|
err := obj.MakeBucketWithLocation(ctx, bucket, BucketOptions{})
|
||
5 years ago
|
if err != nil {
|
||
|
t.Fatalf("Failed to make a bucket %v", err)
|
||
|
}
|
||
|
|
||
|
// Object for test case 1 - No StorageClass defined, no MetaData in PutObject
|
||
|
object1 := "object1"
|
||
5 years ago
|
_, err = obj.PutObject(ctx, bucket, object1, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), opts)
|
||
5 years ago
|
if err != nil {
|
||
|
t.Fatalf("Failed to putObject %v", err)
|
||
|
}
|
||
|
|
||
5 years ago
|
parts1, errs1 := readAllFileInfo(ctx, erasureDisks, bucket, object1, "")
|
||
5 years ago
|
|
||
|
// Object for test case 2 - No StorageClass defined, MetaData in PutObject requesting RRS Class
|
||
|
object2 := "object2"
|
||
|
metadata2 := make(map[string]string)
|
||
|
metadata2["x-amz-storage-class"] = storageclass.RRS
|
||
5 years ago
|
_, err = obj.PutObject(ctx, bucket, object2, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata2})
|
||
5 years ago
|
if err != nil {
|
||
|
t.Fatalf("Failed to putObject %v", err)
|
||
|
}
|
||
|
|
||
5 years ago
|
parts2, errs2 := readAllFileInfo(ctx, erasureDisks, bucket, object2, "")
|
||
5 years ago
|
|
||
|
// Object for test case 3 - No StorageClass defined, MetaData in PutObject requesting Standard Storage Class
|
||
|
object3 := "object3"
|
||
|
metadata3 := make(map[string]string)
|
||
|
metadata3["x-amz-storage-class"] = storageclass.STANDARD
|
||
5 years ago
|
_, err = obj.PutObject(ctx, bucket, object3, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata3})
|
||
5 years ago
|
if err != nil {
|
||
|
t.Fatalf("Failed to putObject %v", err)
|
||
|
}
|
||
|
|
||
5 years ago
|
parts3, errs3 := readAllFileInfo(ctx, erasureDisks, bucket, object3, "")
|
||
5 years ago
|
|
||
|
// Object for test case 4 - Standard StorageClass defined as Parity 6, MetaData in PutObject requesting Standard Storage Class
|
||
|
object4 := "object4"
|
||
|
metadata4 := make(map[string]string)
|
||
|
metadata4["x-amz-storage-class"] = storageclass.STANDARD
|
||
5 years ago
|
globalStorageClass = storageclass.Config{
|
||
5 years ago
|
Standard: storageclass.StorageClass{
|
||
|
Parity: 6,
|
||
|
},
|
||
|
}
|
||
|
|
||
5 years ago
|
_, err = obj.PutObject(ctx, bucket, object4, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata4})
|
||
5 years ago
|
if err != nil {
|
||
|
t.Fatalf("Failed to putObject %v", err)
|
||
|
}
|
||
|
|
||
5 years ago
|
parts4, errs4 := readAllFileInfo(ctx, erasureDisks, bucket, object4, "")
|
||
5 years ago
|
|
||
|
// Object for test case 5 - RRS StorageClass defined as Parity 2, MetaData in PutObject requesting RRS Class
|
||
|
// Reset global storage class flags
|
||
|
object5 := "object5"
|
||
|
metadata5 := make(map[string]string)
|
||
|
metadata5["x-amz-storage-class"] = storageclass.RRS
|
||
5 years ago
|
globalStorageClass = storageclass.Config{
|
||
5 years ago
|
RRS: storageclass.StorageClass{
|
||
|
Parity: 2,
|
||
|
},
|
||
|
}
|
||
|
|
||
5 years ago
|
_, err = obj.PutObject(ctx, bucket, object5, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata5})
|
||
5 years ago
|
if err != nil {
|
||
|
t.Fatalf("Failed to putObject %v", err)
|
||
|
}
|
||
|
|
||
5 years ago
|
parts5, errs5 := readAllFileInfo(ctx, erasureDisks, bucket, object5, "")
|
||
5 years ago
|
|
||
|
// Object for test case 6 - RRS StorageClass defined as Parity 2, MetaData in PutObject requesting Standard Storage Class
|
||
|
object6 := "object6"
|
||
|
metadata6 := make(map[string]string)
|
||
|
metadata6["x-amz-storage-class"] = storageclass.STANDARD
|
||
5 years ago
|
globalStorageClass = storageclass.Config{
|
||
5 years ago
|
RRS: storageclass.StorageClass{
|
||
|
Parity: 2,
|
||
|
},
|
||
|
}
|
||
|
|
||
5 years ago
|
_, err = obj.PutObject(ctx, bucket, object6, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata6})
|
||
5 years ago
|
if err != nil {
|
||
|
t.Fatalf("Failed to putObject %v", err)
|
||
|
}
|
||
|
|
||
5 years ago
|
parts6, errs6 := readAllFileInfo(ctx, erasureDisks, bucket, object6, "")
|
||
5 years ago
|
|
||
|
// Object for test case 7 - Standard StorageClass defined as Parity 5, MetaData in PutObject requesting RRS Class
|
||
|
// Reset global storage class flags
|
||
|
object7 := "object7"
|
||
|
metadata7 := make(map[string]string)
|
||
|
metadata7["x-amz-storage-class"] = storageclass.RRS
|
||
5 years ago
|
globalStorageClass = storageclass.Config{
|
||
5 years ago
|
Standard: storageclass.StorageClass{
|
||
|
Parity: 5,
|
||
|
},
|
||
|
}
|
||
|
|
||
5 years ago
|
_, err = obj.PutObject(ctx, bucket, object7, mustGetPutObjReader(t, bytes.NewReader(data), int64(len(data)), "", ""), ObjectOptions{UserDefined: metadata7})
|
||
5 years ago
|
if err != nil {
|
||
|
t.Fatalf("Failed to putObject %v", err)
|
||
|
}
|
||
|
|
||
5 years ago
|
parts7, errs7 := readAllFileInfo(ctx, erasureDisks, bucket, object7, "")
|
||
5 years ago
|
|
||
|
tests := []struct {
|
||
5 years ago
|
parts []FileInfo
|
||
5 years ago
|
errs []error
|
||
|
expectedReadQuorum int
|
||
|
expectedWriteQuorum int
|
||
|
expectedError error
|
||
|
}{
|
||
|
{parts1, errs1, 8, 9, nil},
|
||
|
{parts2, errs2, 14, 15, nil},
|
||
|
{parts3, errs3, 8, 9, nil},
|
||
|
{parts4, errs4, 10, 11, nil},
|
||
|
{parts5, errs5, 14, 15, nil},
|
||
|
{parts6, errs6, 8, 9, nil},
|
||
|
{parts7, errs7, 14, 15, nil},
|
||
|
}
|
||
5 years ago
|
for _, tt := range tests {
|
||
|
tt := tt
|
||
|
t.(*testing.T).Run("", func(t *testing.T) {
|
||
|
actualReadQuorum, actualWriteQuorum, err := objectQuorumFromMeta(ctx, *xl, tt.parts, tt.errs)
|
||
|
if tt.expectedError != nil && err == nil {
|
||
|
t.Errorf("Expected %s, got %s", tt.expectedError, err)
|
||
|
}
|
||
|
if tt.expectedError == nil && err != nil {
|
||
|
t.Errorf("Expected %s, got %s", tt.expectedError, err)
|
||
|
}
|
||
|
if tt.expectedReadQuorum != actualReadQuorum {
|
||
|
t.Errorf("Expected Read Quorum %d, got %d", tt.expectedReadQuorum, actualReadQuorum)
|
||
|
}
|
||
|
if tt.expectedWriteQuorum != actualWriteQuorum {
|
||
|
t.Errorf("Expected Write Quorum %d, got %d", tt.expectedWriteQuorum, actualWriteQuorum)
|
||
|
}
|
||
|
})
|
||
5 years ago
|
}
|
||
|
}
|