Enhancement for Erasure encode test. (#2287)

master
karthic rao 8 years ago committed by Harshavardhana
parent efbf7dbc0f
commit 091d80666a
  1. 105
      erasure-createfile_test.go
  2. 29
      erasure-utils_test.go
  3. 35
      erasure_test.go

@ -19,6 +19,7 @@ package main
import ( import (
"bytes" "bytes"
"crypto/rand" "crypto/rand"
"github.com/klauspost/reedsolomon"
"testing" "testing"
) )
@ -95,3 +96,107 @@ func TestErasureCreateFile(t *testing.T) {
t.Error("Expected errXLWriteQuorum error") t.Error("Expected errXLWriteQuorum error")
} }
} }
// TestErasureEncode checks for encoding for different data sets.
func TestErasureEncode(t *testing.T) {
// Collection of cases for encode cases.
testEncodeCases := []struct {
inputData []byte
inputDataBlocks int
inputParityBlocks int
shouldPass bool
expectedErr error
}{
// TestCase - 1.
// Regular data encoded.
{
[]byte("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."),
8,
8,
true,
nil,
},
// TestCase - 2.
// Empty data errors out.
{
[]byte(""),
8,
8,
false,
reedsolomon.ErrShortData,
},
// TestCase - 3.
// Single byte encoded.
{
[]byte("1"),
4,
4,
true,
nil,
},
// TestCase - 4.
// test case with negative data block.
{
[]byte("1"),
-1,
8,
false,
reedsolomon.ErrInvShardNum,
},
// TestCase - 5.
// test case with negative parity block.
{
[]byte("1"),
8,
-1,
false,
reedsolomon.ErrInvShardNum,
},
// TestCase - 6.
// test case with zero data block.
{
[]byte("1"),
0,
8,
false,
reedsolomon.ErrInvShardNum,
},
// TestCase - 7.
// test case with zero parity block.
{
[]byte("1"),
8,
0,
false,
reedsolomon.ErrInvShardNum,
},
// TestCase - 8.
// test case with data + parity blocks > 255.
// expected to fail with Error Max Shard number.
{
[]byte("1"),
128,
128,
false,
reedsolomon.ErrMaxShardNum,
},
}
// Test encode cases.
for i, testCase := range testEncodeCases {
_, actualErr := encodeData(testCase.inputData, testCase.inputDataBlocks, testCase.inputParityBlocks)
if actualErr != nil && testCase.shouldPass {
t.Errorf("Test %d: Expected to pass but failed instead with \"%s\"", i+1, actualErr)
}
if actualErr == nil && !testCase.shouldPass {
t.Errorf("Test %d: Expected to fail with error <Error> \"%v\", but instead passed", i+1, testCase.expectedErr)
}
// Failed as expected, but does it fail for the expected reason.
if actualErr != nil && !testCase.shouldPass {
if testCase.expectedErr != actualErr {
t.Errorf("Test %d: Expected Error to be \"%v\", but instead found \"%v\" ", i+1, testCase.expectedErr, actualErr)
}
}
}
}

@ -16,15 +16,29 @@
package main package main
import "testing" import (
"testing"
)
// Test for getChunkSize() // Test validates the number hash writers returned.
func TestNewHashWriters(t *testing.T) {
diskNum := 8
hashWriters := newHashWriters(diskNum)
if len(hashWriters) != diskNum {
t.Errorf("Expected %d hashWriters, but instead got %d", diskNum, len(hashWriters))
}
}
// Tests validate the output of getChunkSize.
func TestGetChunkSize(t *testing.T) { func TestGetChunkSize(t *testing.T) {
// Refer to comments on getChunkSize() for details. // Refer to comments on getChunkSize() for details.
testCases := []struct { testCases := []struct {
blockSize int64 blockSize int64
dataBlocks int dataBlocks int
chunkSize int64 // expected result.
expectedChunkSize int64
}{ }{
{ {
10, 10,
@ -43,11 +57,10 @@ func TestGetChunkSize(t *testing.T) {
}, },
} }
// Verify getChunkSize() for the test cases. // Verify getChunkSize() for the test cases.
for i, test := range testCases { for i, testCase := range testCases {
expected := test.chunkSize got := getChunkSize(testCase.blockSize, testCase.dataBlocks)
got := getChunkSize(test.blockSize, test.dataBlocks) if testCase.expectedChunkSize != got {
if expected != got { t.Errorf("Test %d : expected=%d got=%d", i+1, testCase.expectedChunkSize, got)
t.Errorf("Test %d : expected=%d got=%d", i+1, expected, got)
} }
} }
} }

@ -81,41 +81,6 @@ var encodingMatrices = []encodingMatrix{
{8, 8}, // 8 data, 8 parity blocks. {8, 8}, // 8 data, 8 parity blocks.
} }
// TestErasureEncode checks for encoding for different data sets.
func TestErasureEncode(t *testing.T) {
// Collection of cases for encode cases.
testEncodeCases := []struct {
inputData []byte
shouldPass bool
}{
// Regular data encoded.
{
inputData: []byte("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."),
shouldPass: true,
},
// Empty data errors out.
{
inputData: []byte(""),
shouldPass: false,
},
// Single byte encoded.
{
inputData: []byte("1"),
shouldPass: true,
},
}
// Test encode cases.
for i, testCase := range testEncodeCases {
for _, encodingMatrix := range encodingMatrices {
_, err := encodeData(testCase.inputData, encodingMatrix.dataBlocks, encodingMatrix.parityBlocks)
if err != nil && testCase.shouldPass {
t.Errorf("Test %d: Expected to pass by failed instead with %s, for matrix %v", i+1, err, encodingMatrix)
}
}
}
}
// Tests erasure decoding functionality for various types of inputs. // Tests erasure decoding functionality for various types of inputs.
func TestErasureDecode(t *testing.T) { func TestErasureDecode(t *testing.T) {
data := []byte("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.") data := []byte("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.")

Loading…
Cancel
Save