Browse Source
* stable-5.4: (82 commits) Export all packages of o.e.j.ant and o.e.j.archive bundles Do not require test bundles to export all packages Fix API problem filters Increase severity of AmbiguousMethodReference to ERROR [error prone] suppress AmbiguousMethodReference in AnyLongObjectId [error prone] fix ReferenceEquality warning in CommitBuilder [error prone] suppress NonAtomicVolatileUpdate warning in SimpleLruCache [error prone] fix ReferenceEquality warning in CommitGraphPane#authorFor [error prone] fix ReferenceEquality warning in RevWalk#isMergedInto [error prone] fix ReferenceEquality warning in RefUpdate#updateImpl [error prone] fix ReferenceEquality warning in static equals methods [error prone] suppress AmbiguousMethodReference in AnyObjectId [error prone] fix "FutureReturnValueIgnored" error in FS Fix formatting and add missing braces in Repository#stripWorkDir Repository: fix reference comparison of Files MergeAlgorithm: Suppress Error Prone warning about reference equality Fix NarrowingCompoundAssignment warnings from Error Prone FS_POSIX: handle Files.getFileStore() failures Fix OpenSshConfigTest#config FileSnapshot: fix bug with timestamp thresholding In LockFile#waitForStatChange wait in units of file time resolution Cache FileStoreAttributeCache per directory Fix FileSnapshot#save(long) and FileSnapshot#save(Instant) Persist minimal racy threshold and allow manual configuration Measure minimum racy interval to auto-configure FileSnapshot Reuse FileUtils to recursively delete files created by tests Fix FileAttributeCache.toString() Add test for racy git detection in FileSnapshot Repeat RefDirectoryTest.testGetRef_DiscoversModifiedLoose 100 times Fix org.eclipse.jdt.core.prefs of org.eclipse.jgit.junit Add missing javadoc in org.eclipse.jgit.junit Enhance RepeatRule to report number of failures at the end Fix FileSnapshotTests for filesystem with high timestamp resolution Retry deleting test files in FileBasedConfigTest Measure filesystem timestamp resolution already in test setup Refactor FileSnapshotTest to use NIO APIs Measure stored timestamp resolution instead of time to touch file Handle CancellationException in FileStoreAttributeCache Fix FileSnapshot#saveNoConfig Use Instant for smudge time in DirCache and DirCacheEntry Use Instant instead of milliseconds for filesystem timestamp handling Workaround SecurityException in FS#getFsTimestampResolution Fix NPE in FS$FileStoreAttributeCache.getFsTimestampResolution FS: ignore AccessDeniedException when measuring timestamp resolution Add debug trace for FileSnapshot Use FileChannel.open to touch file and set mtime to now Persist filesystem timestamp resolution and allow manual configuration Increase bazel timeout for long running tests Bazel: Fix lint warning flagged by buildifier Update bazlets to latest version Bazel: Add missing dependencies for ArchiveCommandTest Bazel: Remove FileTreeIteratorWithTimeControl from BUILD file Add support for nanoseconds and microseconds for Config#getTimeUnit Optionally measure filesystem timestamp resolution asynchronously Delete unused FileTreeIteratorWithTimeControl FileSnapshot#equals: consider UNKNOWN_SIZE Timeout measuring file timestamp resolution after 2 seconds Fix RacyGitTests#testRacyGitDetection GlobalBundleCache: Fix ClassNewInstance warning from Error Prone IncorrectObjectTypeException: Fix typos in constructors' Javadoc Change RacyGitTests to create a racy git situation in a stable way Deprecate Constants.CHARACTER_ENCODING in favor of StandardCharsets.UTF_8 Fix non-deterministic hash of archives created by ArchiveCommand Update Maven plugins ecj, plexus, error-prone Update Maven plugins and cleanup Maven warnings Make inner classes static where possible Error Prone: Increase severity of NonOverridingEquals to ERROR Error Prone: Increase severity of ImmutableEnumChecker to ERROR GitDateParser#ParseableSimpleDateFormat: Make formatStr private final BatchRefUpdateTest: Suppress ImmutableEnumChecker warning PacketLineIn: Suppress comparison warnings for END and DELIM FileSnapshot#toString: Suppress ReferenceEquality warnings Blame: Suppress ReferenceEquality warning for RevCommit instances Fix API problem filters pgm: add missing optional dependency to org.tukaani:xz NetscapeCookieFile: Make hash static and group overloaded write NetscapeCookieFile: Javadoc fixes Config: Handle reference-equality warning (and empty javadoc) Error Prone: Increase severity of ShortCircuitBoolean to ERROR ObjectWalk: Prefer boolean operators over logical operators in comparisons BasePackFetchConnection: Prefer boolean operators over logical operators in comparisons PackWriter: Prefer boolean operators over logical operators in comparisons Change-Id: I825fd55bcb5345fb7afe066bf54ca50325f40acb Signed-off-by: David Pursehouse <david.pursehouse@gmail.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>stable-5.5
Matthias Sohn
5 years ago
133 changed files with 3402 additions and 864 deletions
@ -0,0 +1,99 @@
|
||||
/* |
||||
* Copyright (C) 2019, Matthias Sohn <matthias.sohn@sap.com> |
||||
* and other copyright owners as documented in the project's IP log. |
||||
* |
||||
* This program and the accompanying materials are made available |
||||
* under the terms of the Eclipse Distribution License v1.0 which |
||||
* accompanies this distribution, is reproduced below, and is |
||||
* available at http://www.eclipse.org/org/documents/edl-v10.php
|
||||
* |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or |
||||
* without modification, are permitted provided that the following |
||||
* conditions are met: |
||||
* |
||||
* - Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* - Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following |
||||
* disclaimer in the documentation and/or other materials provided |
||||
* with the distribution. |
||||
* |
||||
* - Neither the name of the Eclipse Foundation, Inc. nor the |
||||
* names of its contributors may be used to endorse or promote |
||||
* products derived from this software without specific prior |
||||
* written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
package org.eclipse.jgit.junit.time; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.UncheckedIOException; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
import java.nio.file.attribute.FileTime; |
||||
import java.time.Instant; |
||||
|
||||
import org.eclipse.jgit.util.FS; |
||||
|
||||
/** |
||||
* Utility methods for handling timestamps |
||||
*/ |
||||
public class TimeUtil { |
||||
/** |
||||
* Set the lastModified time of a given file by adding a given offset to the |
||||
* current lastModified time |
||||
* |
||||
* @param path |
||||
* path of a file to set last modified |
||||
* @param offsetMillis |
||||
* offset in milliseconds, if negative the new lastModified time |
||||
* is offset before the original lastModified time, otherwise |
||||
* after the original time |
||||
* @return the new lastModified time |
||||
*/ |
||||
public static Instant setLastModifiedWithOffset(Path path, |
||||
long offsetMillis) { |
||||
Instant mTime = FS.DETECTED.lastModifiedInstant(path) |
||||
.plusMillis(offsetMillis); |
||||
try { |
||||
Files.setLastModifiedTime(path, FileTime.from(mTime)); |
||||
return mTime; |
||||
} catch (IOException e) { |
||||
throw new UncheckedIOException(e); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Set the lastModified time of file a to the one from file b |
||||
* |
||||
* @param a |
||||
* file to set lastModified time |
||||
* @param b |
||||
* file to read lastModified time from |
||||
*/ |
||||
public static void setLastModifiedOf(Path a, Path b) { |
||||
Instant mTime = FS.DETECTED.lastModifiedInstant(b); |
||||
try { |
||||
Files.setLastModifiedTime(a, FileTime.from(mTime)); |
||||
} catch (IOException e) { |
||||
throw new UncheckedIOException(e); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<component id="org.eclipse.jgit.lfs" version="2"> |
||||
<resource path="src/org/eclipse/jgit/lfs/lib/AnyLongObjectId.java" type="org.eclipse.jgit.lfs.lib.AnyLongObjectId"> |
||||
<filter id="1141899266"> |
||||
<message_arguments> |
||||
<message_argument value="5.4"/> |
||||
<message_argument value="5.5"/> |
||||
<message_argument value="isEqual(AnyLongObjectId, AnyLongObjectId)"/> |
||||
</message_arguments> |
||||
</filter> |
||||
</resource> |
||||
</component> |
@ -1,109 +0,0 @@
|
||||
/* |
||||
* Copyright (C) 2010, Christian Halstrick <christian.halstrick@sap.com> |
||||
* and other copyright owners as documented in the project's IP log. |
||||
* |
||||
* This program and the accompanying materials are made available |
||||
* under the terms of the Eclipse Distribution License v1.0 which |
||||
* accompanies this distribution, is reproduced below, and is |
||||
* available at http://www.eclipse.org/org/documents/edl-v10.php
|
||||
* |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or |
||||
* without modification, are permitted provided that the following |
||||
* conditions are met: |
||||
* |
||||
* - Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* - Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following |
||||
* disclaimer in the documentation and/or other materials provided |
||||
* with the distribution. |
||||
* |
||||
* - Neither the name of the Eclipse Foundation, Inc. nor the |
||||
* names of its contributors may be used to endorse or promote |
||||
* products derived from this software without specific prior |
||||
* written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
package org.eclipse.jgit.treewalk; |
||||
|
||||
import java.io.File; |
||||
import java.util.SortedSet; |
||||
import java.util.TreeSet; |
||||
|
||||
import org.eclipse.jgit.lib.Config; |
||||
import org.eclipse.jgit.lib.ObjectReader; |
||||
import org.eclipse.jgit.lib.Repository; |
||||
import org.eclipse.jgit.util.FS; |
||||
|
||||
/** |
||||
* A {@link FileTreeIterator} used in tests which allows to specify explicitly |
||||
* what will be returned by {@link #getEntryLastModified()}. This allows to |
||||
* write tests where certain files have to have the same modification time. |
||||
* <p> |
||||
* This iterator is configured by a list of strictly increasing long values |
||||
* t(0), t(1), ..., t(n). For each file with a modification between t(x) and |
||||
* t(x+1) [ t(x) <= time < t(x+1) ] this iterator will report t(x). For |
||||
* files with a modification time smaller t(0) a modification time of 0 is |
||||
* returned. For files with a modification time greater or equal t(n) t(n) will |
||||
* be returned. |
||||
* <p> |
||||
* This class was written especially to test racy-git problems |
||||
*/ |
||||
public class FileTreeIteratorWithTimeControl extends FileTreeIterator { |
||||
private TreeSet<Long> modTimes; |
||||
|
||||
public FileTreeIteratorWithTimeControl(FileTreeIterator p, Repository repo, |
||||
TreeSet<Long> modTimes) { |
||||
super(p, repo.getWorkTree(), repo.getFS()); |
||||
this.modTimes = modTimes; |
||||
} |
||||
|
||||
public FileTreeIteratorWithTimeControl(FileTreeIterator p, File f, FS fs, |
||||
TreeSet<Long> modTimes) { |
||||
super(p, f, fs); |
||||
this.modTimes = modTimes; |
||||
} |
||||
|
||||
public FileTreeIteratorWithTimeControl(Repository repo, |
||||
TreeSet<Long> modTimes) { |
||||
super(repo); |
||||
this.modTimes = modTimes; |
||||
} |
||||
|
||||
public FileTreeIteratorWithTimeControl(File f, FS fs, |
||||
TreeSet<Long> modTimes) { |
||||
super(f, fs, new Config().get(WorkingTreeOptions.KEY)); |
||||
this.modTimes = modTimes; |
||||
} |
||||
|
||||
@Override |
||||
public AbstractTreeIterator createSubtreeIterator(ObjectReader reader) { |
||||
return new FileTreeIteratorWithTimeControl(this, |
||||
((FileEntry) current()).getFile(), fs, modTimes); |
||||
} |
||||
|
||||
@Override |
||||
public long getEntryLastModified() { |
||||
if (modTimes == null) |
||||
return 0; |
||||
Long cutOff = Long.valueOf(super.getEntryLastModified() + 1); |
||||
SortedSet<Long> head = modTimes.headSet(cutOff); |
||||
return head.isEmpty() ? 0 : head.last().longValue(); |
||||
} |
||||
} |
@ -0,0 +1,135 @@
|
||||
/* |
||||
* Copyright (C) 2019, Matthias Sohn <matthias.sohn@sap.com> |
||||
* and other copyright owners as documented in the project's IP log. |
||||
* |
||||
* This program and the accompanying materials are made available |
||||
* under the terms of the Eclipse Distribution License v1.0 which |
||||
* accompanies this distribution, is reproduced below, and is |
||||
* available at http://www.eclipse.org/org/documents/edl-v10.php
|
||||
* |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or |
||||
* without modification, are permitted provided that the following |
||||
* conditions are met: |
||||
* |
||||
* - Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* - Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following |
||||
* disclaimer in the documentation and/or other materials provided |
||||
* with the distribution. |
||||
* |
||||
* - Neither the name of the Eclipse Foundation, Inc. nor the |
||||
* names of its contributors may be used to endorse or promote |
||||
* products derived from this software without specific prior |
||||
* written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
package org.eclipse.jgit.util; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
import static org.junit.Assert.assertNotNull; |
||||
import static org.junit.Assert.assertNull; |
||||
|
||||
import java.io.IOException; |
||||
import java.nio.file.Files; |
||||
import java.nio.file.Path; |
||||
|
||||
import org.junit.After; |
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
|
||||
public class SimpleLruCacheTest { |
||||
|
||||
private Path trash; |
||||
|
||||
private SimpleLruCache<String, String> cache; |
||||
|
||||
|
||||
@Before |
||||
public void setup() throws IOException { |
||||
trash = Files.createTempDirectory("tmp_"); |
||||
cache = new SimpleLruCache<>(100, 0.2f); |
||||
} |
||||
|
||||
@Before |
||||
@After |
||||
public void tearDown() throws Exception { |
||||
FileUtils.delete(trash.toFile(), |
||||
FileUtils.RECURSIVE | FileUtils.SKIP_MISSING); |
||||
} |
||||
|
||||
@Test |
||||
public void testPutGet() { |
||||
cache.put("a", "A"); |
||||
cache.put("z", "Z"); |
||||
assertEquals("A", cache.get("a")); |
||||
assertEquals("Z", cache.get("z")); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void testPurgeFactorTooLarge() { |
||||
cache.configure(5, 1.01f); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void testPurgeFactorTooLarge2() { |
||||
cache.configure(5, 100); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void testPurgeFactorTooSmall() { |
||||
cache.configure(5, 0); |
||||
} |
||||
|
||||
@Test(expected = IllegalArgumentException.class) |
||||
public void testPurgeFactorTooSmall2() { |
||||
cache.configure(5, -100); |
||||
} |
||||
|
||||
@Test |
||||
public void testGetMissing() { |
||||
assertEquals(null, cache.get("a")); |
||||
} |
||||
|
||||
@Test |
||||
public void testPurge() { |
||||
for (int i = 0; i < 101; i++) { |
||||
cache.put("a" + i, "a" + i); |
||||
} |
||||
assertEquals(80, cache.size()); |
||||
assertNull(cache.get("a0")); |
||||
assertNull(cache.get("a20")); |
||||
assertNotNull(cache.get("a21")); |
||||
assertNotNull(cache.get("a99")); |
||||
} |
||||
|
||||
@Test |
||||
public void testConfigure() { |
||||
for (int i = 0; i < 100; i++) { |
||||
cache.put("a" + i, "a" + i); |
||||
} |
||||
assertEquals(100, cache.size()); |
||||
cache.configure(10, 0.3f); |
||||
assertEquals(7, cache.size()); |
||||
assertNull(cache.get("a0")); |
||||
assertNull(cache.get("a92")); |
||||
assertNotNull(cache.get("a93")); |
||||
assertNotNull(cache.get("a99")); |
||||
} |
||||
} |
@ -0,0 +1,137 @@
|
||||
/* |
||||
* Copyright (C) 2019, Matthias Sohn <matthias.sohn@sap.com> |
||||
* and other copyright owners as documented in the project's IP log. |
||||
* |
||||
* This program and the accompanying materials are made available |
||||
* under the terms of the Eclipse Distribution License v1.0 which |
||||
* accompanies this distribution, is reproduced below, and is |
||||
* available at http://www.eclipse.org/org/documents/edl-v10.php
|
||||
* |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or |
||||
* without modification, are permitted provided that the following |
||||
* conditions are met: |
||||
* |
||||
* - Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* |
||||
* - Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following |
||||
* disclaimer in the documentation and/or other materials provided |
||||
* with the distribution. |
||||
* |
||||
* - Neither the name of the Eclipse Foundation, Inc. nor the |
||||
* names of its contributors may be used to endorse or promote |
||||
* products derived from this software without specific prior |
||||
* written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
*/ |
||||
package org.eclipse.jgit.util; |
||||
|
||||
import static org.junit.Assert.assertEquals; |
||||
import static org.junit.Assert.assertTrue; |
||||
|
||||
import org.eclipse.jgit.util.Stats; |
||||
import org.junit.Test; |
||||
|
||||
public class StatsTest { |
||||
@Test |
||||
public void testStatsTrivial() { |
||||
Stats s = new Stats(); |
||||
s.add(1); |
||||
s.add(1); |
||||
s.add(1); |
||||
assertEquals(3, s.count()); |
||||
assertEquals(1.0, s.min(), 1E-6); |
||||
assertEquals(1.0, s.max(), 1E-6); |
||||
assertEquals(1.0, s.avg(), 1E-6); |
||||
assertEquals(0.0, s.var(), 1E-6); |
||||
assertEquals(0.0, s.stddev(), 1E-6); |
||||
} |
||||
|
||||
@Test |
||||
public void testStats() { |
||||
Stats s = new Stats(); |
||||
s.add(1); |
||||
s.add(2); |
||||
s.add(3); |
||||
s.add(4); |
||||
assertEquals(4, s.count()); |
||||
assertEquals(1.0, s.min(), 1E-6); |
||||
assertEquals(4.0, s.max(), 1E-6); |
||||
assertEquals(2.5, s.avg(), 1E-6); |
||||
assertEquals(1.666667, s.var(), 1E-6); |
||||
assertEquals(1.290994, s.stddev(), 1E-6); |
||||
} |
||||
|
||||
@Test |
||||
/** |
||||
* see |
||||
* https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Example
|
||||
*/ |
||||
public void testStatsCancellationExample1() { |
||||
Stats s = new Stats(); |
||||
s.add(1E8 + 4); |
||||
s.add(1E8 + 7); |
||||
s.add(1E8 + 13); |
||||
s.add(1E8 + 16); |
||||
assertEquals(4, s.count()); |
||||
assertEquals(1E8 + 4, s.min(), 1E-6); |
||||
assertEquals(1E8 + 16, s.max(), 1E-6); |
||||
assertEquals(1E8 + 10, s.avg(), 1E-6); |
||||
assertEquals(30, s.var(), 1E-6); |
||||
assertEquals(5.477226, s.stddev(), 1E-6); |
||||
} |
||||
|
||||
@Test |
||||
/** |
||||
* see |
||||
* https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Example
|
||||
*/ |
||||
public void testStatsCancellationExample2() { |
||||
Stats s = new Stats(); |
||||
s.add(1E9 + 4); |
||||
s.add(1E9 + 7); |
||||
s.add(1E9 + 13); |
||||
s.add(1E9 + 16); |
||||
assertEquals(4, s.count()); |
||||
assertEquals(1E9 + 4, s.min(), 1E-6); |
||||
assertEquals(1E9 + 16, s.max(), 1E-6); |
||||
assertEquals(1E9 + 10, s.avg(), 1E-6); |
||||
assertEquals(30, s.var(), 1E-6); |
||||
assertEquals(5.477226, s.stddev(), 1E-6); |
||||
} |
||||
|
||||
@Test |
||||
public void testNoValues() { |
||||
Stats s = new Stats(); |
||||
assertTrue(Double.isNaN(s.var())); |
||||
assertTrue(Double.isNaN(s.stddev())); |
||||
assertTrue(Double.isNaN(s.avg())); |
||||
assertTrue(Double.isNaN(s.min())); |
||||
assertTrue(Double.isNaN(s.max())); |
||||
s.add(42.3); |
||||
assertTrue(Double.isNaN(s.var())); |
||||
assertTrue(Double.isNaN(s.stddev())); |
||||
assertEquals(42.3, s.avg(), 1E-6); |
||||
assertEquals(42.3, s.max(), 1E-6); |
||||
assertEquals(42.3, s.min(), 1E-6); |
||||
s.add(42.3); |
||||
assertEquals(0, s.var(), 1E-6); |
||||
assertEquals(0, s.stddev(), 1E-6); |
||||
} |
||||
} |
@ -0,0 +1,161 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<component id="org.eclipse.jgit" version="2"> |
||||
<resource path="src/org/eclipse/jgit/dircache/DirCacheEntry.java" type="org.eclipse.jgit.dircache.DirCacheEntry"> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="getLastModifiedInstant()"/> |
||||
</message_arguments> |
||||
</filter> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="mightBeRacilyClean(Instant)"/> |
||||
</message_arguments> |
||||
</filter> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="setLastModified(Instant)"/> |
||||
</message_arguments> |
||||
</filter> |
||||
</resource> |
||||
<resource path="src/org/eclipse/jgit/lib/AnyObjectId.java" type="org.eclipse.jgit.lib.AnyObjectId"> |
||||
<filter id="1141899266"> |
||||
<message_arguments> |
||||
<message_argument value="5.4"/> |
||||
<message_argument value="5.5"/> |
||||
<message_argument value="isEqual(AnyObjectId, AnyObjectId)"/> |
||||
</message_arguments> |
||||
</filter> |
||||
</resource> |
||||
<resource path="src/org/eclipse/jgit/lib/ConfigConstants.java" type="org.eclipse.jgit.lib.ConfigConstants"> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="CONFIG_FILESYSTEM_SECTION"/> |
||||
</message_arguments> |
||||
</filter> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="CONFIG_KEY_MIN_RACY_THRESHOLD"/> |
||||
</message_arguments> |
||||
</filter> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="CONFIG_KEY_TIMESTAMP_RESOLUTION"/> |
||||
</message_arguments> |
||||
</filter> |
||||
</resource> |
||||
<resource path="src/org/eclipse/jgit/storage/file/FileBasedConfig.java" type="org.eclipse.jgit.storage.file.FileBasedConfig"> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="load(boolean)"/> |
||||
</message_arguments> |
||||
</filter> |
||||
</resource> |
||||
<resource path="src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java" type="org.eclipse.jgit.treewalk.WorkingTreeIterator"> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="getEntryLastModifiedInstant()"/> |
||||
</message_arguments> |
||||
</filter> |
||||
</resource> |
||||
<resource path="src/org/eclipse/jgit/treewalk/WorkingTreeIterator.java" type="org.eclipse.jgit.treewalk.WorkingTreeIterator$Entry"> |
||||
<filter id="336695337"> |
||||
<message_arguments> |
||||
<message_argument value="org.eclipse.jgit.treewalk.WorkingTreeIterator.Entry"/> |
||||
<message_argument value="getLastModifiedInstant()"/> |
||||
</message_arguments> |
||||
</filter> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="getLastModifiedInstant()"/> |
||||
</message_arguments> |
||||
</filter> |
||||
</resource> |
||||
<resource path="src/org/eclipse/jgit/util/FS.java" type="org.eclipse.jgit.util.FS"> |
||||
<filter id="338792546"> |
||||
<message_arguments> |
||||
<message_argument value="org.eclipse.jgit.util.FS"/> |
||||
<message_argument value="getFsTimerResolution(Path)"/> |
||||
</message_arguments> |
||||
</filter> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="getFileStoreAttributes(Path)"/> |
||||
</message_arguments> |
||||
</filter> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="lastModifiedInstant(File)"/> |
||||
</message_arguments> |
||||
</filter> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="lastModifiedInstant(Path)"/> |
||||
</message_arguments> |
||||
</filter> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="setAsyncFileStoreAttributes(boolean)"/> |
||||
</message_arguments> |
||||
</filter> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="setLastModified(Path, Instant)"/> |
||||
</message_arguments> |
||||
</filter> |
||||
</resource> |
||||
<resource path="src/org/eclipse/jgit/util/FS.java" type="org.eclipse.jgit.util.FS$Attributes"> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="getLastModifiedInstant()"/> |
||||
</message_arguments> |
||||
</filter> |
||||
</resource> |
||||
<resource path="src/org/eclipse/jgit/util/FS.java" type="org.eclipse.jgit.util.FS$FileStoreAttributes"> |
||||
<filter id="1142947843"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="FileStoreAttributes"/> |
||||
</message_arguments> |
||||
</filter> |
||||
</resource> |
||||
<resource path="src/org/eclipse/jgit/util/References.java" type="org.eclipse.jgit.util.References"> |
||||
<filter id="1108344834"> |
||||
<message_arguments> |
||||
<message_argument value="5.4"/> |
||||
<message_argument value="5.5"/> |
||||
<message_argument value="org.eclipse.jgit.util.References"/> |
||||
</message_arguments> |
||||
</filter> |
||||
</resource> |
||||
<resource path="src/org/eclipse/jgit/util/SimpleLruCache.java" type="org.eclipse.jgit.util.SimpleLruCache"> |
||||
<filter id="1109393411"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="org.eclipse.jgit.util.SimpleLruCache"/> |
||||
</message_arguments> |
||||
</filter> |
||||
</resource> |
||||
<resource path="src/org/eclipse/jgit/util/Stats.java" type="org.eclipse.jgit.util.Stats"> |
||||
<filter id="1109393411"> |
||||
<message_arguments> |
||||
<message_argument value="5.1.9"/> |
||||
<message_argument value="org.eclipse.jgit.util.Stats"/> |
||||
</message_arguments> |
||||
</filter> |
||||
</resource> |
||||
</component> |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue