Skip to content

Commit

Permalink
Add tests (#15)
Browse files Browse the repository at this point in the history
* Add tests

* Create master javadoc for all subprojects

* Generate Javadocs to gh-pages

* Provide credentials for Travis to update gh-pages

* Only publish docs on merge to master

* Better way to exclude checkstyle for generated sources

* Throw exception instead of print stacktrace
  • Loading branch information
justinjc authored Nov 7, 2017
1 parent 6c11b6c commit 4be8e3d
Show file tree
Hide file tree
Showing 23 changed files with 1,678 additions and 103 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ env:
- secure: "md8HXICzWoRCi5sk2aGgPP8947okH2Vlvr+5Ka67mVLd42JOtWx3EE13cvB9UqUVPLM/qreb6mFCb97xNI+5L4mr9pX+CllxANsWbNA3qwVGwxCUdXwXMokpm9KYUsvJG132PJv4fIzGDe4qpwb5kT6tH1zxcxdqXvMlqAwMP57oTHXGtMSwCpy6pzhILnOsf9BqiiS+jkT17yM9p5NEvxgtJBfFOqZO/iO8kyCqN6eaRtAlw8pxh1nplUiJdXwpU+ZKG7Dl5HHRDfyZenhgFWGctbsaNqfy2Aj9fKjCYznMJ47cA2h+36bprCKvRDQ4r67AeJr+joF9mubQBriVGokuS2kiCAmDaf70mwcm+GP08uxbUGY45DTELbyB+iPsz3mR8YKclir2JPTS6es5oE6wvQSSLLOquwku6mwGQQ5BAdu9CwECd3weYykGSz0FpbzLguP0D/Ad0lH1tdmrfADQvVUfDPr716QyWSA4X1Nd1oMKm6pjVh86Jfub2AM7UCTfopG3Uibjc7+u2yQZa2tIq376ssR4SHSzU+W3uAOOVbhPSsf1GyVDtt129qSATV8fZzCSZkRdZODGhwn98TmzVxKY1dPNWUwhQ1ioRqjnCwU70pWKzF34wsR2YnuODK8RvzCrDztwbJ5Lm+FuGFC9cagXwz8wQMHCNhdq1Ls="
- secure: "wznPpNu1ANjLfn8N/vOK0jxUR5uX49pbM7cqMto1HAEC6iOqdl9y0PfJxhKH0Um9bmGkoDN5RlToK4WIfBKiF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zEHWtQQMpDTX+M4o0D2d01lse8JppkFFyUVFTw2D9FBDOpl0UQy46zTV6mwM3BnfTCP60LXKs6stDMVqHdyNU8Ss27+Sl+WqMDfJKDlxzAcBlvIkPKIBbjZDSLPoxQ45ZqhezHMSfKPD7cI62U5eK2pqmNZmntb7r5GkOwW+YWKJA243PZUuhopaKmb53uqhLZr3HKs5NwW1YRIRUVaQ="
- secure: "mflZomMfNZKCYX09mU1nWcFtmKvoy+hxEKfQi29jMSbLF3O4jtPQFWkIkLq9qmDiQq2boZlaZtFcHYccmWDNGJ0wMDaHmJ6dwfMhuAMtnkuJQCMDMLRVun7cKh5LN6CYlVILdeEk/019Mngj+VLQXyyNnjjs0pWUhwGy87BeFlgDyMXVhzaEx28QgoG4eiQdOIneTYUehcR4yAIoehwIaY2P/udnu0lmLuiVyg/OiY8T7tStmSytmtTE1L9xyPqPp2n4snQ64NNeFfy2qYgz407AH0ORFrwnGa73iTRSIH71JbCY/23iw4jBFod/0RVFY/arvdE8stELA5ziqEEiknIGEfqS5apCVYJkOt1it8s8EL8n2BmoTmfkxAVtdoilWy63NmzVmLRwt9bY0jwaK8pgQ0t37DJqAiIHsC2Om6O9TGhP+dNuKuG3l2OQ+GbbkNAx3mnGzjfNb3GIdU4c8nUkVK5K6K2QsTkuI4G+cBMtibTITH+HFrsz7guWnCQSXymcGAI+YfaluFQ7mJfALKbve9xAZ0Amr+BdSAKXF0r9jPwkdx11M12iGVk742Xc5tzGMaRb8MNpqhO7i0j8KT7PJnslUs8sX3P/73WdTgjJo0nu7S6i66mzMCuIlBuLoknImu7H0QjUJNQWmnzsyQrdvXqPU0YqF5BDA0bz8xc="

# As recommended in:
# https://docs.travis-ci.com/user/languages/java/#Caching
Expand All @@ -33,4 +34,4 @@ before_install:
- ./ci/before_install.sh

after_success:
- ./gradlew jacocoRootReport coveralls
- ./ci/after_success.sh
12 changes: 12 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ subprojects {
toolVersion = '6.19'
}

checkstyleMain.exclude '**/generated/**/*'

ext."signing.secretKeyRingFile" = "../ci/${ext.secretKeyRingFileName}"

task sourcesJar(type: Jar, dependsOn: classes) {
Expand Down Expand Up @@ -189,3 +191,13 @@ task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
}

test.finalizedBy jacocoRootReport

// Create javadoc containing all subprojects for full online documentation
test.finalizedBy tasks.create([
name: 'masterJavaDoc',
type: Javadoc,
dependsOn: subprojects.collect{it.getName() + ':classes'}
]) {
classpath = files(subprojects.collect{ it.sourceSets.main.compileClasspath })
source = subprojects.collect{ it.sourceSets.main.allJava }
}
8 changes: 0 additions & 8 deletions checkstyles/suppressions.xml

This file was deleted.

4 changes: 0 additions & 4 deletions checkstyles/uber_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@
<module name="Checker">
<property name="charset" value="UTF-8"/>

<module name="SuppressionFilter">
<property name="file" value="checkstyles/suppressions.xml" />
</module>

<!-- Trailing spaces -->
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
Expand Down
14 changes: 14 additions & 0 deletions ci/after_success.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Generate coverage report
./gradlew jacocoRootReport coveralls

# Publish Javadoc
if [ "$TRAVIS_JDK_VERSION" == "openjdk7" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then
git checkout --orphan gh-pages
git reset
cp -r build/docs/javadoc/ docs
git clean -fdxe /docs
git add -A
git commit -m "Update Javadoc"
git push -f https://${GITHUB_TOKEN}@github.com/uber-java/tally.git gh-pages
fi
131 changes: 131 additions & 0 deletions core/src/test/java/com/uber/m3/tally/BucketPairImplTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package com.uber.m3.tally;

import com.uber.m3.util.Duration;
import org.junit.Test;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class BucketPairImplTest {
@Test
public void bucketPairs() {
BucketPair[] expectedPairs = new BucketPair[]{
new BucketPairImpl(
-Double.MAX_VALUE,
Double.MAX_VALUE,
Duration.MIN_VALUE,
Duration.MAX_VALUE
)
};

assertArrayEquals(expectedPairs, BucketPairImpl.bucketPairs(null));

expectedPairs = new BucketPair[]{
new BucketPairImpl(
-Double.MAX_VALUE,
0,
Duration.MIN_VALUE,
Duration.ZERO
),
new BucketPairImpl(
0,
50,
Duration.ZERO,
Duration.ofSeconds(50)
),
new BucketPairImpl(
50,
100,
Duration.ofSeconds(50),
Duration.ofSeconds(100)
),
new BucketPairImpl(
100,
Double.MAX_VALUE,
Duration.ofSeconds(100),
Duration.MAX_VALUE
),
};

assertArrayEquals(
expectedPairs,
BucketPairImpl.bucketPairs(ValueBuckets.linear(0, 50, 3))
);
}

@Test
public void addZeroBucket() {
BucketPair[] bucketPairs = BucketPairImpl.bucketPairs(
DurationBuckets.linear(Duration.ofMillis(-30), Duration.ofMillis(20), 3)
);

assertEquals(5, bucketPairs.length);

assertEquals(Duration.MIN_VALUE, bucketPairs[0].lowerBoundDuration());
assertEquals(Duration.ofMillis(-30), bucketPairs[0].upperBoundDuration());

assertEquals(Duration.ofMillis(-30), bucketPairs[1].lowerBoundDuration());
assertEquals(Duration.ofMillis(-10), bucketPairs[1].upperBoundDuration());

assertEquals(Duration.ofMillis(-10), bucketPairs[2].lowerBoundDuration());
assertEquals(Duration.ZERO, bucketPairs[2].upperBoundDuration());

assertEquals(Duration.ZERO, bucketPairs[3].lowerBoundDuration());
assertEquals(Duration.ofMillis(10), bucketPairs[3].upperBoundDuration());

assertEquals(Duration.ofMillis(10), bucketPairs[4].lowerBoundDuration());
assertEquals(Duration.MAX_VALUE, bucketPairs[4].upperBoundDuration());
}

@Test
public void testToString() {
BucketPair[] bucketPairs = BucketPairImpl.bucketPairs(
ValueBuckets.linear(-100, 200, 2)
);

// Unlike Duration buckets, we don't add a 0 in the buckets
assertEquals(3, bucketPairs.length);
assertEquals("[-2562047h47m16.854775808s, -1m40s]", bucketPairs[0].toString());
assertEquals("[-1m40s, 1m40s]", bucketPairs[1].toString());
assertEquals("[1m40s, 2562047h47m16.854775807s]", bucketPairs[2].toString());

BucketPair[] emptyBucketPairs = BucketPairImpl.bucketPairs(null);
assertEquals(1, emptyBucketPairs.length);
assertEquals("[-2562047h47m16.854775808s, 2562047h47m16.854775807s]", emptyBucketPairs[0].toString());
}

@Test
public void equalsHashCode() {
BucketPair bucketPair = BucketPairImpl.bucketPairs(null)[0];
BucketPair sameBucketPair = BucketPairImpl.bucketPairs(null)[0];

assertTrue(bucketPair.equals(sameBucketPair));
assertTrue(bucketPair.equals(bucketPair));
assertEquals(bucketPair.hashCode(), sameBucketPair.hashCode());

assertFalse(bucketPair.equals(null));
assertFalse(bucketPair.equals(9));
}
}
60 changes: 60 additions & 0 deletions core/src/test/java/com/uber/m3/tally/CapableOfTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package com.uber.m3.tally;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

public class CapableOfTest {
@Test
public void capabilities() throws Exception {
Capabilities capabilities = new CapableOf(false, true);

assertFalse(capabilities.reporting());
assertTrue(capabilities.tagging());

assertTrue(CapableOf.REPORTING.reporting());
assertFalse(CapableOf.REPORTING.tagging());

assertFalse(CapableOf.NONE.reporting());
assertFalse(CapableOf.NONE.tagging());

assertTrue(CapableOf.REPORTING_TAGGING.reporting());
assertTrue(CapableOf.REPORTING_TAGGING.tagging());
}

@Test
public void equalsHashCode() throws Exception {
assertFalse(CapableOf.NONE.equals(null));
assertFalse(CapableOf.NONE.equals(9));

assertFalse(CapableOf.NONE.equals(CapableOf.REPORTING));
assertFalse(new CapableOf(true, false).equals(new CapableOf(false, true)));

assertTrue(CapableOf.REPORTING.equals(CapableOf.REPORTING));
assertTrue(CapableOf.REPORTING.equals(new CapableOf(true, false)));
assertEquals(CapableOf.REPORTING.hashCode(), new CapableOf(true, false).hashCode());
assertTrue(new CapableOf(false, false).equals(new CapableOf(false, false)));
}
}
10 changes: 5 additions & 5 deletions core/src/test/java/com/uber/m3/tally/CounterImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,25 @@ public void setUp() {
public void inc() {
counter.inc(1);
counter.report("", null, reporter);
assertEquals(1, reporter.prevCounter);
assertEquals(1, reporter.nextCounterVal());

counter.inc(1);
counter.report("", null, reporter);
assertEquals(1, reporter.prevCounter);
assertEquals(1, reporter.nextCounterVal());

counter.inc(1);
counter.inc(1);
counter.report("", null, reporter);
assertEquals(2, reporter.prevCounter);
assertEquals(2, reporter.nextCounterVal());

counter.inc(3);
counter.report("", null, reporter);
assertEquals(3, reporter.prevCounter);
assertEquals(3, reporter.nextCounterVal());

counter.inc(1);
counter.inc(-3);
counter.report("", null, reporter);
assertEquals(-2, reporter.prevCounter);
assertEquals(-2, reporter.nextCounterVal());
}

@Test
Expand Down
Loading

0 comments on commit 4be8e3d

Please sign in to comment.