XL: listOnlineDisks should use modTime instead of version. (#2166)
This change is needed to make reading from objects future proof in-terms of handling online disks. Our current counter is not based on affirmative knowledge and relies on arithmetic sequence which can lead to bugs. Using modTime simplifies the understanding of `xl.json` and future tooling / debugging of the format.master
parent
e5cd35aad0
commit
623e0f9243
@ -0,0 +1,83 @@ |
|||||||
|
/* |
||||||
|
* Minio Cloud Storage, (C) 2016 Minio, Inc. |
||||||
|
* |
||||||
|
* 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. |
||||||
|
*/ |
||||||
|
|
||||||
|
package main |
||||||
|
|
||||||
|
import ( |
||||||
|
"testing" |
||||||
|
"time" |
||||||
|
) |
||||||
|
|
||||||
|
// validates functionality provided to find most common
|
||||||
|
// time occurrence from a list of time.
|
||||||
|
func TestCommonTime(t *testing.T) { |
||||||
|
// List of test cases for common modTime.
|
||||||
|
testCases := []struct { |
||||||
|
times []time.Time |
||||||
|
time time.Time |
||||||
|
}{ |
||||||
|
{ |
||||||
|
// 1. Tests common times when slice has varying time elements.
|
||||||
|
[]time.Time{ |
||||||
|
time.Unix(0, 1).UTC(), |
||||||
|
time.Unix(0, 2).UTC(), |
||||||
|
time.Unix(0, 3).UTC(), |
||||||
|
time.Unix(0, 3).UTC(), |
||||||
|
time.Unix(0, 2).UTC(), |
||||||
|
time.Unix(0, 3).UTC(), |
||||||
|
time.Unix(0, 1).UTC(), |
||||||
|
}, time.Unix(0, 3).UTC(), |
||||||
|
}, |
||||||
|
{ |
||||||
|
// 2. Tests common time obtained when all elements are equal.
|
||||||
|
[]time.Time{ |
||||||
|
time.Unix(0, 3).UTC(), |
||||||
|
time.Unix(0, 3).UTC(), |
||||||
|
time.Unix(0, 3).UTC(), |
||||||
|
time.Unix(0, 3).UTC(), |
||||||
|
time.Unix(0, 3).UTC(), |
||||||
|
time.Unix(0, 3).UTC(), |
||||||
|
time.Unix(0, 3).UTC(), |
||||||
|
}, time.Unix(0, 3).UTC(), |
||||||
|
}, |
||||||
|
{ |
||||||
|
// 3. Tests common time obtained when elements have a mixture
|
||||||
|
// of sentinel values.
|
||||||
|
[]time.Time{ |
||||||
|
time.Unix(0, 3).UTC(), |
||||||
|
time.Unix(0, 3).UTC(), |
||||||
|
time.Unix(0, 2).UTC(), |
||||||
|
time.Unix(0, 1).UTC(), |
||||||
|
time.Unix(0, 3).UTC(), |
||||||
|
time.Unix(0, 4).UTC(), |
||||||
|
time.Unix(0, 3).UTC(), |
||||||
|
timeSentinel, |
||||||
|
timeSentinel, |
||||||
|
timeSentinel, |
||||||
|
}, time.Unix(0, 3).UTC(), |
||||||
|
}, |
||||||
|
} |
||||||
|
|
||||||
|
// Tests all the testcases, and validates them against expected
|
||||||
|
// common modtime. Tests fail if modtime does not match.
|
||||||
|
for i, testCase := range testCases { |
||||||
|
// Obtain a common mod time from modTimes slice.
|
||||||
|
ctime := commonTime(testCase.times) |
||||||
|
if testCase.time != ctime { |
||||||
|
t.Fatalf("Test case %d, expect to pass but failed. Wanted modTime: %s, got modTime: %s\n", i+1, testCase.time, ctime) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue