@@ -81,7 +81,25 @@ public void testSimpleEncodeDecode() {
81
81
new byte [] { 2 , 4 },
82
82
new byte [] { 3 , 5 }
83
83
};
84
- runEncodeDecode (dataShards );
84
+ runEncodeDecode (5 , 5 , dataShards );
85
+ }
86
+
87
+ /**
88
+ * Try encoding and decoding with a lot of shards.
89
+ */
90
+ @ Test
91
+ public void testBigEncodeDecode () {
92
+ final Random random = new Random (0 );
93
+ final int dataCount = 64 ;
94
+ final int parityCount = 64 ;
95
+ final int shardSize = 200 ;
96
+ byte [] [] dataShards = new byte [dataCount ] [shardSize ];
97
+ for (byte [] shard : dataShards ) {
98
+ for (int i = 0 ; i < shard .length ; i ++) {
99
+ shard [i ] = (byte ) random .nextInt (256 );
100
+ }
101
+ }
102
+ runEncodeDecode (dataCount , parityCount , dataShards );
85
103
}
86
104
87
105
/**
@@ -90,35 +108,36 @@ public void testSimpleEncodeDecode() {
90
108
*
91
109
* Uses 5+5 coding, so there must be 5 input data shards.
92
110
*/
93
- private void runEncodeDecode (byte [][] dataShards ) {
111
+ private void runEncodeDecode (int dataCount , int parityCount , byte [][] dataShards ) {
94
112
113
+ final int totalCount = dataCount + parityCount ;
95
114
final int shardLength = dataShards [0 ].length ;
96
115
97
116
// Make the list of data and parity shards.
98
- assertEquals (5 , dataShards .length );
117
+ assertEquals (dataCount , dataShards .length );
99
118
final int dataLength = dataShards [0 ].length ;
100
- byte [] [] allShards = new byte [10 ] [];
101
- for (int i = 0 ; i < 5 ; i ++) {
119
+ byte [] [] allShards = new byte [totalCount ] [];
120
+ for (int i = 0 ; i < dataCount ; i ++) {
102
121
allShards [i ] = Arrays .copyOf (dataShards [i ], dataLength );
103
122
}
104
- for (int i = 5 ; i < 10 ; i ++) {
123
+ for (int i = dataCount ; i < totalCount ; i ++) {
105
124
allShards [i ] = new byte [dataLength ];
106
125
}
107
126
108
127
// Encode.
109
- ReedSolomon codec = ReedSolomon .create (5 , 5 );
128
+ ReedSolomon codec = ReedSolomon .create (dataCount , parityCount );
110
129
codec .encodeParity (allShards , 0 , dataLength );
111
130
112
131
// Make a copy to decode with.
113
- byte [] [] testShards = new byte [10 ] [];
114
- boolean [] shardPresent = new boolean [10 ];
115
- for (int i = 0 ; i < 10 ; i ++) {
132
+ byte [] [] testShards = new byte [totalCount ] [];
133
+ boolean [] shardPresent = new boolean [totalCount ];
134
+ for (int i = 0 ; i < totalCount ; i ++) {
116
135
testShards [i ] = Arrays .copyOf (allShards [i ], shardLength );
117
136
shardPresent [i ] = true ;
118
137
}
119
138
120
139
// Decode with 0, 1, ..., 5 shards missing.
121
- for (int numberMissing = 0 ; numberMissing < 6 ; numberMissing ++) {
140
+ for (int numberMissing = 0 ; numberMissing < parityCount + 1 ; numberMissing ++) {
122
141
tryAllSubsetsMissing (codec , allShards , testShards , shardPresent , numberMissing );
123
142
}
124
143
}
0 commit comments