diff --git a/.gitignore b/.gitignore index f3ac701..2f7896d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ -/target -integration-credentials.properties +target/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index da24710..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: java - -jdk: - - oraclejdk7 - - openjdk6 - -notifications: - email: - - tech@tempo-db.com diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 0b1eac0..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,7 +0,0 @@ -## 1.1.5 - -* Updated the pom for release to maven central. - -## 1.1.2 - -* URL escape series keys. Note: this is a potentially breaking change if you have been pre-escaping series keys. This release will cause the key to be double-encoded. You can safely stop escaping the key outside of this library. diff --git a/LICENSE b/LICENSE index cb4dd03..87d6c50 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2013 TempoDB Inc. +Copyright (c) 2012 TempoDB Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index af2f72a..c7018c2 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,7 @@ ## TempoDB Java API Client - -[![Build Status](https://travis-ci.org/tempodb/tempodb-java.png?branch=1.0)](https://travis-ci.org/tempodb/tempodb-java) - -Releases are available on our maven server. Ensure that you can pull from maven central, -and add the following dependency to your pom: - - - com.tempodb - tempodb-java - 1.1.5 - - -Or, you can clone the repository and build with maven. +A release can be downloaded [here](https://github.com/tempodb/tempodb-java/downloads) or +you can clone the repository and build with maven. mvn compile -Javadocs are located [here](http://tempodb.github.com/tempodb-java/javadocs/1.1.2/) +Javadocs are located [here](http://tempodb.github.com/tempodb-java/javadocs/apidocs/) diff --git a/pom.xml b/pom.xml index 49232bc..1678080 100644 --- a/pom.xml +++ b/pom.xml @@ -1,247 +1,149 @@ - + 4.0.0 - com.tempodb tempodb-java - 1.1.6-SNAPSHOT jar - + 0.4.0 tempodb-java - http://github.com/tempodb/tempodb-java - TempoDB REST Client - - scm:git:file://${basedir} - scm:git:file://${basedir} - http://github.com/tempodb/tempodb - HEAD - - - - tempodb - TempoDB Open Source - opensource@tempo-db.com - http://tempo-db.com - - - - - The MIT License - http://www.opensource.org/licenses/mit-license.php - repo - - - + http://maven.apache.org UTF-8 UTF-8 - - src/integration-test - ${integration-test.directory}/java - ${integration-test.directory}/resources - ${project.build.directory}/integrationtest-classes + - - - release-sign-artifacts - - - performRelease - true - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.4 - - ${gpg.passphrase} - - - - sign-artifacts - verify - - sign - - - - - - - - + + commons-codec + commons-codec + 1.4 + - - - sonatype-nexus-staging - Sonatype Nexus release repository - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - sonatype-nexus-snapshots - Sonatype Nexus snapshot repository - https://oss.sonatype.org/content/repositories/snapshots - - + + commons-logging + commons-logging + 1.1.1 + - org.apache.httpcomponents httpclient - 4.2.5 + 4.1.3 + - org.apache.commons - commons-lang3 - 3.1 + org.apache.httpcomponents + httpclient-cache + 4.1.3 + - joda-time - joda-time - 2.3 + org.apache.httpcomponents + httpcore + 4.1.4 + + + + org.apache.httpcomponents + httpmime + 4.1.3 + + + org.json + json + 20090211 + + + + com.fasterxml.jackson.core + jackson-databind + 2.0.0 + + + + com.fasterxml.jackson.core + jackson-annotations + 2.0.0 + + + + com.fasterxml.jackson.core + jackson-core + 2.0.0 + + com.fasterxml.jackson.datatype jackson-datatype-joda - 2.2.3 + 2.0.0-RC3 - junit - junit - 4.8.2 - test + joda-time + joda-time + 2.1 + - org.mockito - mockito-core - 1.9.5 + junit + junit + 3.8.1 test - + + + + src/main/resources + true + + org.apache.maven.plugins - maven-compiler-plugin - 3.1 + maven-javadoc-plugin + 2.8.1 - 1.6 - 1.6 - -Xlint:unchecked + com.tempodb.examples - org.codehaus.mojo - build-helper-maven-plugin - 1.8 - - - add-test-source - generate-test-sources - - add-test-source - - - - ${integration-test.testSourceDirectory} - - - - - add-test-resource - generate-test-resources - - add-test-resource - - - - - ${integration-test.docDirectory} - ${integration-test.testOutputDirectory} - - - - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 2.16 - - - - integration-test - verify - - - - - - org.apache.maven.plugins - maven-source-plugin - 2.0.4 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 + maven-assembly-plugin + 2.3 - - http://www.joda.org/joda-time/apidocs/ - http://fasterxml.github.io/jackson-databind/javadoc/2.2.0/ - - -J-Xmx2G + false + ${project.build.directory}/releases/ + + ${basedir}/src/main/assemblies/targz-bin.xml + ${basedir}/src/main/assemblies/zip-bin.xml + - - attach-javadocs - - jar - - + + package + + single + + - org.codehaus.mojo - findbugs-maven-plugin - 2.5.2 - - Max - Default - true - - + maven-dependency-plugin - - - check - - + + prepare-package + + copy-dependencies + + + ${project.build.directory}/lib + + - - org.apache.maven.plugins - maven-release-plugin - 2.4.1 - - v@{project.version} - true - - + diff --git a/src/integration-test/java/com/tempodb/ClientIT.java b/src/integration-test/java/com/tempodb/ClientIT.java deleted file mode 100644 index 646b623..0000000 --- a/src/integration-test/java/com/tempodb/ClientIT.java +++ /dev/null @@ -1,401 +0,0 @@ -package com.tempodb; - -import java.io.File; -import java.io.FileInputStream; -import java.net.InetSocketAddress; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; - -import static com.tempodb.util.Preconditions.*; - - -public class ClientIT { - private static final Client client; - private static final Client invalidClient; - private static final DateTimeZone timezone = DateTimeZone.UTC; - private static final DateTime start = new DateTime(1500, 1, 1, 0, 0, 0, 0, timezone); - private static final DateTime end = new DateTime(3000, 1, 1, 0, 0, 0, 0, timezone); - private static final Interval interval = new Interval(start, end); - - private static final int SLEEP = 5000; - - static { - File credentials = new File("integration-credentials.properties"); - if(!credentials.exists()) { - String message = "Missing credentials file for integration test.\n" + - "Please supply a file 'integration-credentials.properties' with the following format:\n" + - " database.id=\n" + - " credentials.key=\n" + - " credentials.secret=\n" + - " hostname=\n" + - " port=\n" + - " scheme=\n"; - - System.out.println(message); - System.exit(1); - } - - client = getClient(credentials); - invalidClient = new Client(client.getDatabase(), new Credentials("key", "secret"), - client.getHost(), client.getScheme()); - } - - static Client getClient(File propertiesFile) { - Properties properties = new Properties(); - try { - properties.load(new FileInputStream(propertiesFile)); - } catch (Exception e) { - throw new IllegalArgumentException("No credentials file", e); - } - - String id = checkNotNull(properties.getProperty("database.id")); - String key = checkNotNull(properties.getProperty("credentials.key")); - String secret = checkNotNull(properties.getProperty("credentials.secret")); - String hostname = checkNotNull(properties.getProperty("hostname")); - int port = Integer.parseInt(checkNotNull(properties.getProperty("port"))); - String scheme = checkNotNull(properties.getProperty("scheme")); - - Database database = new Database(id); - Credentials credentials = new Credentials(key, secret); - InetSocketAddress host = new InetSocketAddress(hostname, port); - return new Client(database, credentials, host, scheme); - } - - @BeforeClass - static public void onetimeSetup() { - cleanup(); - } - - static public void cleanup() { - /* Delete all datapoints all series */ - Cursor cursor = client.getSeries(new Filter()); - for(Series series : cursor) { - Result result = client.deleteDataPoints(series, interval); - assertEquals(State.SUCCESS, result.getState()); - } - - /* Delete all series */ - Result result = client.deleteAllSeries(); - assertEquals(State.SUCCESS, result.getState()); - } - - @After - public void tearDown() { cleanup(); } - - @Test - public void testInvalidCredentials() { - Series series = new Series("key1", "", new HashSet(), new HashMap()); - Result result = invalidClient.createSeries(series); - Result expected = new Result(null, 403, "Forbidden"); - assertEquals(expected, result); - } - - @Test - public void testCreateSeries() { - HashSet tags = new HashSet(); - tags.add("create"); - - Series series = new Series("create-series", "name", tags, new HashMap()); - - Result result = client.createSeries(series); - Result expected = new Result(series, 200, "OK"); - - assertEquals(expected, result); - } - - @Test - public void testDeleteDataPointsBySeries() throws InterruptedException { - // Write datapoints - DataPoint dp = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 12.34); - Result result1 = client.writeDataPoints(new Series("key1"), Arrays.asList(dp)); - assertEquals(State.SUCCESS, result1.getState()); - Thread.sleep(SLEEP); - - // Read datapoints - List expected1 = Arrays.asList(dp); - Cursor cursor1 = client.readDataPoints(new Series("key1"), interval, timezone); - assertEquals(expected1, toList(cursor1)); - - // Delete datapoints - Result result2 = client.deleteDataPoints(new Series("key1"), interval); - assertEquals(new Result(null, 200, "OK"), result2); - - // Read datapoints again - List expected2 = new ArrayList(); - Cursor cursor2 = client.readDataPoints(new Series("key1"), interval, timezone); - assertEquals(expected2, toList(cursor2)); - } - - @Test - public void testWriteDataPointBySeries() { - DataPoint dp = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 12.34); - Result result = client.writeDataPoints(new Series("key1"), Arrays.asList(dp)); - assertEquals(State.SUCCESS, result.getState()); - } - - @Test - public void testFindDataPointBySeries() throws InterruptedException { - DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 2, 0, 0 ,0, 0, timezone), 23.45); - DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 2, 1, 0 ,0, 0, timezone), 34.56); - - Result result = client.writeDataPoints(new Series("key-find"), Arrays.asList(dp1, dp2)); - assertEquals(State.SUCCESS, result.getState()); - Thread.sleep(SLEEP); - - DateTime start = new DateTime(2012, 1, 2, 0, 0, 0, 0, timezone); - DateTime end = new DateTime(2012, 1, 3, 0, 0, 0, 0, timezone); - Interval interval = new Interval(start, end); - Predicate predicate = new Predicate(Period.days(1), "max"); - DataPointFound dpf1 = new DataPointFound(interval, dp2); - - List expected = Arrays.asList(dpf1); - Cursor cursor = client.findDataPoints(new Series("key-find"), new Interval(start, end), predicate, timezone); - assertEquals(expected, toList(cursor)); - } - - @Test - public void testReadDataPointByKey() throws InterruptedException { - DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 2, 0, 0 ,0, 0, timezone), 23.45); - DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 2, 1, 0 ,0, 0, timezone), 34.56); - - Result result = client.writeDataPoints(new Series("key1"), Arrays.asList(dp1, dp2)); - assertEquals(State.SUCCESS, result.getState()); - Thread.sleep(SLEEP); - - DateTime start = new DateTime(2012, 1, 2, 0, 0, 0, 0, timezone); - DateTime end = new DateTime(2012, 1, 3, 0, 0, 0, 0, timezone); - - List expected = Arrays.asList(dp1, dp2); - Cursor cursor = client.readDataPoints(new Series("key1"), new Interval(start, end), timezone); - assertEquals(expected, toList(cursor)); - } - - @Test - public void testReadSingleValue() throws InterruptedException { - DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 2, 0, 0 ,0, 0, timezone), 23.45); - DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 2, 1, 0 ,0, 0, timezone), 34.56); - - Result result = client.writeDataPoints(new Series("key1"), Arrays.asList(dp1, dp2)); - assertEquals(State.SUCCESS, result.getState()); - Thread.sleep(SLEEP); - - DateTime ts = new DateTime(2012, 1, 2, 0, 0, 0, 0, timezone); - - SingleValue expected = new SingleValue(new Series("key1"), new DataPoint(ts, 23.45)); - Result value = client.readSingleValue(new Series("key1"), ts, timezone, Direction.EXACT); - assertEquals(expected, value.getValue()); - } - - @Test - public void testReadMultiDataPoints() throws InterruptedException { - WriteRequest wr = new WriteRequest() - .add(new Series("key1"), new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 5.0)) - .add(new Series("key2"), new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 6.0)) - .add(new Series("key1"), new DataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0, timezone), 7.0)) - .add(new Series("key2"), new DataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0, timezone), 8.0)); - - Result result1 = client.writeDataPoints(wr); - assertEquals(new Result(null, 200, "OK"), result1); - - Thread.sleep(SLEEP); - - Filter filter = new Filter(); - filter.addKey("key1"); - filter.addKey("key2"); - Cursor cursor = client.readMultiDataPoints(filter, interval, timezone); - - Map data1 = new HashMap(); - data1.put("key1", 5.0); - data1.put("key2", 6.0); - - Map data2 = new HashMap(); - data2.put("key1", 7.0); - data2.put("key2", 8.0); - - List expected = Arrays.asList( - new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), data1), - new MultiDataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0, timezone), data2) - ); - assertEquals(expected, toList(cursor)); - } - - @Test - public void testReadMultiRollupDataPointByKey() throws InterruptedException { - DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 2, 0, 0 ,0, 0, timezone), 23.45); - DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 2, 1, 0 ,0, 0, timezone), 34.56); - - Result result = client.writeDataPoints(new Series("key1"), Arrays.asList(dp1, dp2)); - assertEquals(State.SUCCESS, result.getState()); - Thread.sleep(SLEEP); - - DateTime start = new DateTime(2012, 1, 2, 0, 0, 0, 0, timezone); - DateTime end = new DateTime(2012, 1, 3, 0, 0, 0, 0, timezone); - MultiRollup rollup = new MultiRollup(Period.days(1), new Fold[] { Fold.MAX, Fold.MIN }); - - Cursor cursor = client.readMultiRollupDataPoints(new Series("key1"), new Interval(start, end), timezone, rollup); - - Map data1 = new HashMap(); - data1.put("max", 34.56); - data1.put("min", 23.45); - - MultiDataPoint mdp1 = new MultiDataPoint(new DateTime(2012, 1, 2, 0, 0, 0, 0, timezone), data1); - List expected = Arrays.asList(mdp1); - - assertEquals(expected, toList(cursor)); - } - - @Test - public void testWriteDataPoints() throws InterruptedException { - WriteRequest wr = new WriteRequest() - .add(new Series("key1"), new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 5.0)) - .add(new Series("key2"), new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 6.0)) - .add(new Series("key1"), new DataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0, timezone), 7.0)) - .add(new Series("key2"), new DataPoint(new DateTime(2012, 1, 1, 0, 2, 0, 0, timezone), 8.0)); - - Thread.sleep(SLEEP); - - Result result = client.writeDataPoints(wr); - assertEquals(new Result(null, 200, "OK"), result); - } - - @Test - public void testReadDataPoints() throws InterruptedException { - WriteRequest wr = new WriteRequest() - .add(new Series("key1"), new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 5.0)) - .add(new Series("key2"), new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 6.0)) - .add(new Series("key1"), new DataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0, timezone), 7.0)) - .add(new Series("key2"), new DataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0, timezone), 8.0)); - - Result result1 = client.writeDataPoints(wr); - assertEquals(new Result(null, 200, "OK"), result1); - - Thread.sleep(SLEEP); - - Filter filter = new Filter(); - filter.addKey("key1"); - filter.addKey("key2"); - Aggregation aggregation = new Aggregation(Fold.SUM); - Cursor cursor = client.readDataPoints(filter, interval, timezone, aggregation); - - DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone), 11.0); - DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0, timezone), 15.0); - List expected = Arrays.asList(dp1, dp2); - assertEquals(expected, toList(cursor)); - } - - @Test - public void testGetSeriesByKey() { - // Create a series - HashMap attributes = new HashMap(); - attributes.put("appidÜ", "1234"); - attributes.put("txn", "/def ault"); - - Series series = new Series("appidÜ:1234.txn:/def ault.cou+()+={}nt", "name", new HashSet(), attributes); - Result result1 = client.createSeries(series); - - // Get the series - Result result2 = client.getSeries("appidÜ:1234.txn:/def ault.cou+()+={}nt"); - Result expected = new Result(series, 200, "OK"); - assertEquals(expected, result2); - } - - @Test - public void testGetSeriesByFilter() { - // Create a series - HashSet tags = new HashSet(); - tags.add("get-filter"); - Series series = new Series("create-series", "name", tags, new HashMap()); - Result result1 = client.createSeries(series); - - // Get the series by filter - Filter filter = new Filter(); - filter.addTag("get-filter"); - Cursor cursor = client.getSeries(filter); - List expected = Arrays.asList(series); - assertEquals(expected, toList(cursor)); - } - - @Test - public void testUpdateSeries() { - // Create a series - HashSet tags = new HashSet(); - tags.add("update"); - Series series = new Series("update-series", "name", tags, new HashMap()); - Result result1 = client.createSeries(series); - - // Update the series - series.getTags().add("update2"); - Result result2 = client.updateSeries(series); - assertEquals(new Result(series, 200, "OK"), result2); - - // Get the series - Result result3 = client.getSeries("update-series"); - Result expected = new Result(series, 200, "OK"); - assertEquals(expected, result3); - } - - @Test - public void testDeleteSeries() { - // Create a series - HashSet tags = new HashSet(); - tags.add("delete"); - Series series = new Series("delete-series", "name", tags, new HashMap()); - Result result1 = client.createSeries(series); - - // Delete the series - Result result2 = client.deleteSeries(series); - assertEquals(new Result(null, 200, "OK"), result2); - - // Get the series - Result result3 = client.getSeries("delete-series"); - Result expected = new Result(null, 403, "Forbidden"); - assertEquals(expected, result3); - } - - @Test - public void testDeleteSeriesByFilter() { - // Create a series - HashSet tags = new HashSet(); - tags.add("delete-filter"); - Series series1 = new Series("delete-series", "name", tags, new HashMap()); - Series series2 = new Series("delete-series2", "name", new HashSet(), new HashMap()); - Result result1 = client.createSeries(series1); - Result result2 = client.createSeries(series2); - - // Get the series by filter - Filter filter = new Filter(); - filter.addTag("delete-filter"); - Cursor cursor = client.getSeries(filter); - List expected1 = Arrays.asList(series1); - assertEquals(expected1, toList(cursor)); - - // Delete the series by filter - Result result3 = client.deleteSeries(filter); - assertEquals(new Result(new DeleteSummary(1), 200, "OK"), result3); - - // Get the series by filter again - Cursor cursor2 = client.getSeries(filter); - List expected2 = Arrays.asList(); - assertEquals(expected2, toList(cursor2)); - } - - private List toList(Cursor cursor) { - List output = new ArrayList(); - for(T dp : cursor) { - output.add(dp); - } - return output; - } -} diff --git a/src/integration-test/resources/integration-credentials.properties.example b/src/integration-test/resources/integration-credentials.properties.example deleted file mode 100644 index c7fd315..0000000 --- a/src/integration-test/resources/integration-credentials.properties.example +++ /dev/null @@ -1,6 +0,0 @@ -database.id= -credentials.key= -credentials.secret= -hostname= -port= -scheme=http diff --git a/src/main/assemblies/common-bin.xml b/src/main/assemblies/common-bin.xml new file mode 100644 index 0000000..52323dc --- /dev/null +++ b/src/main/assemblies/common-bin.xml @@ -0,0 +1,13 @@ + + + + /lib + + + + + README.md + / + + + diff --git a/src/main/assemblies/targz-bin.xml b/src/main/assemblies/targz-bin.xml new file mode 100644 index 0000000..f342f6a --- /dev/null +++ b/src/main/assemblies/targz-bin.xml @@ -0,0 +1,13 @@ + + + targz + + tar.gz + + + true + + + src/main/assemblies/common-bin.xml + + diff --git a/src/main/assemblies/zip-bin.xml b/src/main/assemblies/zip-bin.xml new file mode 100644 index 0000000..6ac0f7a --- /dev/null +++ b/src/main/assemblies/zip-bin.xml @@ -0,0 +1,13 @@ + + + zip + + zip + + + true + + + src/main/assemblies/common-bin.xml + + diff --git a/src/main/java/com/tempodb/Aggregation.java b/src/main/java/com/tempodb/Aggregation.java deleted file mode 100644 index e268778..0000000 --- a/src/main/java/com/tempodb/Aggregation.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.tempodb; - -import java.io.Serializable; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; - -import static com.tempodb.util.Preconditions.*; - - -/** - * The representation of an aggregation between multiple Series. - * - * An Aggregation allows you to specify a new Series that is a mathematical - * operation across multiple Series. For instance, the following Aggregation - * specifies the sum of multiple Series: - * - *

- *  Aggregation aggregation = new Aggregation(Fold.SUM);
- *  
- * @see Fold - * @since 1.0.0 - */ -public class Aggregation implements Serializable { - private Fold fold; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - public Aggregation() { - this(Fold.SUM); - } - - /** - * Base constructor - * @param fold The aggregation's folding function. - * @since 1.0.0 - */ - public Aggregation(Fold fold) { - this.fold = checkNotNull(fold); - } - - /** - * Returns the {@link Fold}. - * @return The aggregation's folding function. - * @since 1.0.0 - */ - public Fold getFold() { return fold; } - - /** - * Sets the {@link Fold}. - * @param fold The folding function to use. - * @since 1.0.0 - */ - public void setFold(Fold fold) { this.fold = checkNotNull(fold); } - - @Override - public String toString() { - return String.format("Aggregation(fold=%s)", fold.toString().toLowerCase()); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(107, 109) - .append(fold) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof Aggregation)) return false; - - Aggregation rhs = (Aggregation)obj; - return new EqualsBuilder() - .append(fold, rhs.fold) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/Client.java b/src/main/java/com/tempodb/Client.java deleted file mode 100644 index f6d753d..0000000 --- a/src/main/java/com/tempodb/Client.java +++ /dev/null @@ -1,1309 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.InetSocketAddress; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URLEncoder; -import java.nio.charset.Charset; -import java.util.List; -import java.util.Map; - -import com.fasterxml.jackson.core.JsonProcessingException; -import org.apache.http.*; -import org.apache.http.auth.*; -import org.apache.http.client.*; -import org.apache.http.client.entity.GzipDecompressingEntity; -import org.apache.http.client.methods.*; -import org.apache.http.client.protocol.ClientContext; -import org.apache.http.client.utils.URIBuilder; -import org.apache.http.conn.ConnectionKeepAliveStrategy; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.auth.BasicScheme; -import org.apache.http.impl.client.*; -import org.apache.http.impl.conn.PoolingClientConnectionManager; -import org.apache.http.message.BasicHeaderElementIterator; -import org.apache.http.message.BasicNameValuePair; -import org.apache.http.params.*; -import org.apache.http.protocol.*; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; - -import com.tempodb.json.Json; -import static com.tempodb.util.Preconditions.*; - -/** - * The main object used to make calls to the TempoDB api. - * - * It is a thin wrapper around the TempoDB Rest API - * - *

A client object holds the session information required to authenticate and connect to the Rest api. An api key and secret - * are required. These can be obtained by signing up at http://tempo-db.com. The client - * also lets you specify a different hostname (for instance, if you are on a dedicated cluster) and port, and whether to - * use SSL encryption on the connection. - * - *

Using the client, you can: - *

    - *
  • Retrieve a filtered list of Series
  • - *
  • Retrieve a Series by key
  • - *
  • Retrieve datapoints for a single series in a specific time interval
  • - *
  • Write datapoints for a single series
  • - *
  • Retrieve datapoints aggregated across multiple Series
  • - *
  • Write datapoints to multiple Series
  • - *
- * - *

The following example initializes a Client object and retrieves datapoints for a Series referenced by the key "my-key" - * for the time period 2012-01-01 to 2010-01-02, returning the hourly average. This calls returns a Cursor<DataPoint> - * which provides a lazily loaded iterable of DataPoints. - * - *

- *    import java.net.InetSocketAddress;
- *    import org.joda.time.DateTime;
- *    import org.joda.time.DateTimeZone;
- *    import org.joda.time.Interval;
- *    import org.joda.time.Period;
- *
- *    Database database = new Database("database-id");
- *    Credentials credentials = new Credentials("api-key", "api-secret");
- *    InetSocketAddress host = new InetSocketAddress("api.tempo-db.com", 443);
- *    Client client = new Client(database, credentials, host, "https");
- *
- *    DateTime start = new DateTime(2012, 1, 1, 0, 0, 0, 0);
- *    DateTime end = new DateTime(2012, 1, 2, 0, 0, 0, 0);
- *    Rollup rollup = new Rollup(Period.hours(1), Fold.MEAN);
- *
- *    Cursor<DataPoint> datapoints = client.readDataPoints(new Series("my-key"), new Interval(start, end), DateTimeZone.UTC, rollup);
- *  
- * - *

The TempoDB Rest API supports http keep-alive, and the Client object is designed to be thread-safe. It is recommended - * that a Client object be created and then reused for subsequent calls. This help to amoritize the cost of setting up the - * http client across many calls. - */ -public class Client { - - private final Database database; - private final Credentials credentials; - private final InetSocketAddress host; - private final String scheme; - - private HttpClient client = null; - private HttpHost target = null; - - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - // Timeout on milliseconds - private static final int DEFAULT_TIMEOUT_MILLIS = 50000; // 50 seconds - private static final long DEFAULT_KEEPALIVE_TIMEOUT_MILLIS = 50000; // 50 seconds - private static final int GENERIC_ERROR_CODE = 600; - private static final String VERSION = "1.0-SNAPSHOT"; - private static final String API_VERSION = "v1"; - private final DateTimeFormatter iso8601 = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); - - private enum HttpMethod { GET, POST, PUT, DELETE } - - /** - * Base constructor for a Client object. - * - * @param database Database to connect to - * @param credentials Api credentials - * @param host Api server host address - * @param scheme Scheme for requests. "http" and "https" are supported. - */ - public Client(Database database, Credentials credentials, InetSocketAddress host, String scheme) { - checkArgument(scheme.equals("http") || scheme.equals("https"), "Scheme must be either \"http\" or \"https\"."); - this.database = checkNotNull(database, "Database cannot be null."); - this.credentials = checkNotNull(credentials, "Credentials cannot be null."); - this.host = checkNotNull(host, "Host cannot be null."); - this.scheme = checkNotNull(scheme, "Scheme cannot be null."); - } - - /** - * Returns the database the client is connected to. - * @return Client database - * @since 1.0.0 - */ - public Database getDatabase() { return database; } - - /** - * Returns the client's credentials. - * @return Api credentials - * @since 1.0.0 - */ - public Credentials getCredentials() { return credentials; } - - /** - * Returns client's api server host. - * @return Api server host address. - * @since 1.0.0 - */ - public InetSocketAddress getHost() { return host; } - - /** - * Returns client's api server scheme. - * @return Api server scheme. - * @since 1.0.0 - */ - public String getScheme() { return scheme; } - - /** - * Creates a Series - * @param series The Series to create - * @return The created Series - * - * @since 1.0.0 - * @throws NullPointerException If the input Series is null. - */ - public Result createSeries(Series series) { - checkNotNull(series); - - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/series/", API_VERSION)); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = "Could not build URI"; - throw new IllegalArgumentException(message, e); - } - - Result result = null; - String body = null; - try { - body = Json.dumps(series); - } catch (JsonProcessingException e) { - String message = "Error serializing the body of the request. More detail: " + e.getMessage(); - result = new Result(null, GENERIC_ERROR_CODE, message); - return result; - } - - HttpRequest request = buildRequest(uri.toString(), HttpMethod.POST, body); - result = execute(request, Series.class); - return result; - } - - /** - * Deletes a range of datapoints for a Series specified by key. - * - * @param series The series - * @param interval The start/end datetime interval to delete. - * @return Void - * - * @since 1.0.0 - */ - public Result deleteDataPoints(Series series, Interval interval) { - checkNotNull(series); - checkNotNull(interval); - - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/data/", API_VERSION, urlencode(series.getKey()))); - addIntervalToURI(builder, interval); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = String.format("Could not build URI with inputs: key: %s, interval: %s", series.getKey(), interval); - throw new IllegalArgumentException(message, e); - } - - HttpRequest request = buildRequest(uri.toString(), HttpMethod.DELETE); - Result result = execute(request, Void.class); - return result; - } - - /** - * Deletes a Series. - * - * @param series The Series to delete - * @return {@link Void} - * @since 1.0.0 - */ - public Result deleteSeries(Series series) { - checkNotNull(series); - - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/", API_VERSION, urlencode(series.getKey()))); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = String.format("Could not build URI with inputs: key: %s", series.getKey()); - throw new IllegalArgumentException(message, e); - } - - HttpRequest request = buildRequest(uri.toString(), HttpMethod.DELETE); - Result result = execute(request, Void.class); - return result; - } - - /** - * Deletes set of series by a filter. - * - * @param filter The series filter @see Filter - * @return A DeleteSummary providing information about the series deleted. - * - * @see DeleteSummary - * @see Filter - * @since 1.0.0 - */ - public Result deleteSeries(Filter filter) { - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/series/", API_VERSION)); - addFilterToURI(builder, filter); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = String.format("Could not build URI with input - filter: %s", filter); - throw new IllegalArgumentException(message, e); - } - - HttpRequest request = buildRequest(uri.toString(), HttpMethod.DELETE); - Result result = execute(request, DeleteSummary.class); - return result; - } - - /** - * Deletes all Series in a database. - * - * @return A DeleteSummary providing information about the series deleted. - * - * @see DeleteSummary - * @since 1.0.0 - */ - public Result deleteAllSeries() { - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/series/", API_VERSION)); - builder.addParameter("allow_truncation", "true"); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = "Could not build URI"; - throw new IllegalArgumentException(message, e); - } - - HttpRequest request = buildRequest(uri.toString(), HttpMethod.DELETE); - Result result = execute(request, DeleteSummary.class); - return result; - } - - /** - * Returns a cursor of intervals/datapoints matching a predicate specified by series. - *

The system default timezone is used for the returned DateTimes. - * - * @param series The series - * @param interval An interval of time for the query (start/end datetimes) - * @param predicate The predicate for the query. - * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Cursor - * @since 1.1.0 - */ - public Cursor findDataPoints(Series series, Interval interval, Predicate predicate) { - return findDataPoints(series, interval, predicate, DateTimeZone.getDefault()); - } - - /** - * Returns a cursor of intervals/datapoints matching a predicate specified by series. - * - * @param series The series - * @param interval An interval of time for the query (start/end datetimes) - * @param predicate The predicate for the query. - * @param timezone The time zone for the returned datapoints. - * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Cursor - * @since 1.1.0 - */ - public Cursor findDataPoints(Series series, Interval interval, Predicate predicate, DateTimeZone timezone) { - checkNotNull(series); - checkNotNull(interval); - checkNotNull(predicate); - checkNotNull(timezone); - - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/find/", API_VERSION, urlencode(series.getKey()))); - addIntervalToURI(builder, interval); - addPredicateToURI(builder, predicate); - addTimeZoneToURI(builder, timezone); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = String.format("Could not build URI with inputs: key: %s, interval: %s, predicate: %s, timezone: %s", series.getKey(), interval, predicate, timezone); - throw new IllegalArgumentException(message, e); - } - - Cursor cursor = new DataPointFoundCursor(uri, this); - return cursor; - } - - /** - * Returns a Series referenced by key. - * - * @param key The Series key to retrieve - * @return The requested Series. - * @since 1.0.0 - */ - public Result getSeries(String key) { - checkNotNull(key); - - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/", API_VERSION, urlencode(key))); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = String.format("Could not build URI with inputs: key: %s", key); - throw new IllegalArgumentException(message, e); - } - - HttpRequest request = buildRequest(uri.toString()); - Result result = execute(request, Series.class); - return result; - } - - /** - * Returns a cursor of series specified by a filter. - * - * @param filter The series filter - * @return A Cursor of Series. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Cursor - * @see Filter - * @since 1.0.0 - */ - public Cursor getSeries(Filter filter) { - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/series/", API_VERSION)); - addFilterToURI(builder, filter); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = String.format("Could not build URI with input - filter: %s", filter); - throw new IllegalArgumentException(message, e); - } - - Cursor cursor = new SeriesCursor(uri, this); - return cursor; - } - - /** - * Reads a single value for a series at a specific timestamp (exact match). - *

The returned value (datapoint) can be null if there are no - * datapoints in the series or in the specified direction. The system default - * timezone is used. - * - * @param series The series to read from - * @param timestamp The timestamp to read a value at - * @return The value at the specified timestamp - * - * @see SingleValue - * @since 1.1.0 - */ - public Result readSingleValue(Series series, DateTime timestamp) { - return readSingleValue(series, timestamp, DateTimeZone.getDefault(), Direction.EXACT); - } - - /** - * Reads a single value for a series at a specific timestamp (exact match). - *

The returned value (datapoint) can be null if there are no - * datapoints in the series or in the specified direction. - * - * @param series The series to read from - * @param timestamp The timestamp to read a value at - * @param timezone The timezone of the returned datapoint - * @return The value at the specified timestamp - * - * @see SingleValue - * @since 1.1.0 - */ - public Result readSingleValue(Series series, DateTime timestamp, DateTimeZone timezone) { - return readSingleValue(series, timestamp, timezone, Direction.EXACT); - } - - /** - * Reads a single value for a series at a specific timestamp. - *

The returned value (datapoint) can be null if there are no - * datapoints in the series or in the specified direction. The system - * default timezone is used. - * - * @param series The series to read from - * @param timestamp The timestamp to read a value at - * @param direction The direction to search if an exact timestamp match is not found - * @return The value at the specified timestamp - * - * @see SingleValue - * @since 1.1.0 - */ - public Result readSingleValue(Series series, DateTime timestamp, Direction direction) { - return readSingleValue(series, timestamp, DateTimeZone.getDefault(), direction); - } - - /** - * Reads a single value for a series at a specific timestamp. - *

The returned value (datapoint) can be null if there are no - * datapoints in the series or in the specified direction. - * - * @param series The series to read from - * @param timestamp The timestamp to read a value at - * @param timezone The timezone of the returned datapoint - * @param direction The direction to search if an exact timestamp match is not found - * @return The value at the specified timestamp - * - * @see SingleValue - * @since 1.1.0 - */ - public Result readSingleValue(Series series, DateTime timestamp, DateTimeZone timezone, Direction direction) { - checkNotNull(series); - checkNotNull(timestamp); - checkNotNull(timezone); - checkNotNull(direction); - - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/single/", API_VERSION, urlencode(series.getKey()))); - addTimestampToURI(builder, timestamp); - addTimeZoneToURI(builder, timezone); - addDirectionToURI(builder, direction); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = String.format("Could not build URI with inputs: key: %s, timestamp: %s, timezone: %s, direction: %s", series.getKey(), timestamp.toString(), timezone.toString(), direction.toString()); - throw new IllegalArgumentException(message, e); - } - - HttpRequest request = buildRequest(uri.toString()); - Result result = execute(request, SingleValue.class); - return result; - } - - /** - * Returns a cursor of single value for a set of series - *

The returned values (datapoints) can be null if there are no - * datapoints in the series or in the specified direction. The - * system default timezone is used. The direction is set to EXACT. - * - * @param filter The filter of series to read from - * @param timestamp The timestamp to read a value at - * @return A cursor over the values at the specified timestamp - * - * @see Cursor - * @see SingleValue - * @since 1.1.0 - */ - public Cursor readSingleValue(Filter filter, DateTime timestamp) { - return readSingleValue(filter, timestamp, DateTimeZone.getDefault(), Direction.EXACT); - } - - /** - * Returns a cursor of single value for a set of series - *

The returned values (datapoints) can be null if there are no - * datapoints in the series or in the specified direction. - * The direction is set to EXACT. - * - * @param filter The filter of series to read from - * @param timestamp The timestamp to read a value at - * @param timezone The timezone of the returned datapoints - * @return A cursor over the values at the specified timestamp - * - * @see Cursor - * @see SingleValue - * @since 1.1.0 - */ - public Cursor readSingleValue(Filter filter, DateTime timestamp, DateTimeZone timezone) { - return readSingleValue(filter, timestamp, timezone, Direction.EXACT); - } - - /** - * Returns a cursor of single value for a set of series - *

The returned values (datapoints) can be null if there are no - * datapoints in the series or in the specified direction. The - * system default timezone is used. - * - * @param filter The filter of series to read from - * @param timestamp The timestamp to read a value at - * @param direction The direction to search if an exact timestamp match is not found - * @return A cursor over the values at the specified timestamp - * - * @see Cursor - * @see SingleValue - * @since 1.1.0 - */ - public Cursor readSingleValue(Filter filter, DateTime timestamp, Direction direction) { - return readSingleValue(filter, timestamp, DateTimeZone.getDefault(), direction); - } - - /** - * Returns a cursor of single value for a set of series - *

The returned values (datapoints) can be null if there are no - * datapoints in the series or in the specified direction. - * - * @param filter The filter of series to read from - * @param timestamp The timestamp to read a value at - * @param timezone The timezone of the returned datapoint - * @param direction The direction to search if an exact timestamp match is not found - * @return A cursor over the values at the specified timestamp - * - * @see Cursor - * @see SingleValue - * @since 1.1.0 - */ - public Cursor readSingleValue(Filter filter, DateTime timestamp, DateTimeZone timezone, Direction direction) { - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/single/", API_VERSION)); - addFilterToURI(builder, filter); - addTimestampToURI(builder, timestamp); - addTimeZoneToURI(builder, timezone); - addDirectionToURI(builder, direction); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = String.format("Could not build URI with input - filter: %s", filter); - throw new IllegalArgumentException(message, e); - } - - Cursor cursor = new SingleValueCursor(uri, this); - return cursor; - } - - /** - * Reads summary statistics for a series for the specified interval. - * - * @param series The series to read from - * @param interval The interval of data to summarize - * @return A set of statistics for an interval of data - * - * @see SingleValue - * @since 1.1.0 - */ - public Result

readSummary(Series series, Interval interval) { - checkNotNull(series); - checkNotNull(interval); - DateTimeZone timezone = interval.getStart().getChronology().getZone(); - - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/summary/", API_VERSION, urlencode(series.getKey()))); - addIntervalToURI(builder, interval); - addTimeZoneToURI(builder, timezone); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = String.format("Could not build URI with inputs: key: %s, interval: %s, timezone: %s", series.getKey(), interval.toString(), timezone.toString()); - throw new IllegalArgumentException(message, e); - } - - HttpRequest request = buildRequest(uri.toString()); - Result result = execute(request, Summary.class); - return result; - } - - /** - * Returns a cursor of datapoints specified by series. - *

The system default timezone is used for the returned DateTimes. - * - * @param series The series - * @param interval An interval of time for the query (start/end datetimes) - * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Cursor - * @since 1.0.0 - */ - public Cursor readDataPoints(Series series, Interval interval) { - return readDataPoints(series, interval, DateTimeZone.getDefault(), null, null); - } - - /** - * Returns a cursor of datapoints specified by series. - * - * @param series The series - * @param interval An interval of time for the query (start/end datetimes) - * @param timezone The time zone for the returned datapoints. - * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Cursor - * @since 1.0.0 - */ - public Cursor readDataPoints(Series series, Interval interval, DateTimeZone timezone) { - return readDataPoints(series, interval, timezone, null, null); - } - - /** - * Returns a cursor of datapoints specified by series. - *

The system default timezone is used for the returned DateTimes. - * - * @param series The series - * @param interval An interval of time for the query (start/end datetimes) - * @param rollup The rollup for the read query. This can be null. - * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Cursor - * @since 1.0.0 - */ - public Cursor readDataPoints(Series series, Interval interval, Rollup rollup) { - return readDataPoints(series, interval, DateTimeZone.getDefault(), rollup, null); - } - - /** - * Returns a cursor of datapoints specified by series. - * - * @param series The series - * @param interval An interval of time for the query (start/end datetimes) - * @param timezone The time zone for the returned datapoints. - * @param rollup The rollup for the read query. This can be null. - * @param interpolation The interpolation for the read query. This can be null. - * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Cursor - * @since 1.0.0 - */ - public Cursor readDataPoints(Series series, Interval interval, DateTimeZone timezone, Rollup rollup, Interpolation interpolation) { - checkNotNull(series); - checkNotNull(interval); - checkNotNull(timezone); - - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/segment/", API_VERSION, urlencode(series.getKey()))); - addInterpolationToURI(builder, interpolation); - addIntervalToURI(builder, interval); - addRollupToURI(builder, rollup); - addTimeZoneToURI(builder, timezone); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = String.format("Could not build URI with inputs: key: %s, interval: %s, rollup: %s, timezone: %s", series.getKey(), interval, rollup, timezone); - throw new IllegalArgumentException(message, e); - } - - Cursor cursor = new DataPointCursor(uri, this); - return cursor; - } - - /** - * Returns a cursor of datapoints specified by series with multiple rollups. - *

The system default timezone is used for the returned DateTimes. - * - * @param series The series - * @param interval An interval of time for the query (start/end datetimes) - * @param rollup The MultiRollup for the read query. - * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Cursor - * @see MultiRollup - * @since 1.1.0 - */ - public Cursor readMultiRollupDataPoints(Series series, Interval interval, MultiRollup rollup) { - return readMultiRollupDataPoints(series, interval, DateTimeZone.getDefault(), rollup, null); - } - - /** - * Returns a cursor of datapoints specified by series with multiple rollups. - * - * @param series The series - * @param interval An interval of time for the query (start/end datetimes) - * @param timezone The time zone for the returned datapoints. - * @param rollup The MultiRollup for the read query. - * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Cursor - * @see MultiRollup - * @since 1.0.0 - */ - public Cursor readMultiRollupDataPoints(Series series, Interval interval, DateTimeZone timezone, MultiRollup rollup) { - return readMultiRollupDataPoints(series, interval, timezone, rollup, null); - } - - /** - * Returns a cursor of datapoints specified by series with multiple rollups. - * - * @param series The series - * @param interval An interval of time for the query (start/end datetimes) - * @param timezone The time zone for the returned datapoints. - * @param rollup The MultiRollup for the read query. - * @param interpolation The interpolation for the read query. This can be null. - * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Cursor - * @see MultiRollup - * @since 1.0.0 - */ - public Cursor readMultiRollupDataPoints(Series series, Interval interval, DateTimeZone timezone, MultiRollup rollup, Interpolation interpolation) { - checkNotNull(series); - checkNotNull(interval); - checkNotNull(timezone); - checkNotNull(rollup); - - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/data/rollups/segment/", API_VERSION, urlencode(series.getKey()))); - addInterpolationToURI(builder, interpolation); - addIntervalToURI(builder, interval); - addMultiRollupToURI(builder, rollup); - addTimeZoneToURI(builder, timezone); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = String.format("Could not build URI with inputs: key: %s, interval: %s, rollup: %s, timezone: %s", series.getKey(), interval, rollup, timezone); - throw new IllegalArgumentException(message, e); - } - - Cursor cursor = new MultiRollupDataPointCursor(uri, this); - return cursor; - } - - /** - * Returns a cursor of datapoints specified by a series filter. - * - *

This endpoint allows one to request multiple series and apply an aggregation function. - * The system default timezone is used for the returned DateTimes. - * - * @param filter The series filter - * @param interval An interval of time for the query (start/end datetimes) - * @param aggregation The aggregation for the read query. This is required. - * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Aggregation - * @see Cursor - * @see Filter - * @since 1.0.0 - */ - public Cursor readDataPoints(Filter filter, Interval interval, Aggregation aggregation) { - return readDataPoints(filter, interval, DateTimeZone.getDefault(), aggregation, null, null); - } - - /** - * Returns a cursor of datapoints specified by a series filter. - * - *

This endpoint allows one to request multiple series and apply an aggregation function. - * The system default timezone is used for the returned DateTimes. - * - * @param filter The series filter - * @param interval An interval of time for the query (start/end datetimes) - * @param aggregation The aggregation for the read query. This is required. - * @param rollup The rollup for the read query. This can be null. - * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Aggregation - * @see Cursor - * @see Filter - * @see Rollup - * @since 1.0.0 - */ - public Cursor readDataPoints(Filter filter, Interval interval, Aggregation aggregation, Rollup rollup) { - return readDataPoints(filter, interval, DateTimeZone.getDefault(), aggregation, rollup, null); - } - - /** - * Returns a cursor of datapoints specified by a series filter. - * - * This endpoint allows one to request multiple series and apply an aggregation function. - * - * @param filter The series filter - * @param interval An interval of time for the query (start/end datetimes) - * @param timezone The time zone for the returned datapoints. - * @param aggregation The aggregation for the read query. This is required. - * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Aggregation - * @see Cursor - * @see Filter - * @since 1.0.0 - */ - public Cursor readDataPoints(Filter filter, Interval interval, DateTimeZone timezone, Aggregation aggregation) { - return readDataPoints(filter, interval, timezone, aggregation, null, null); - } - - /** - * Returns a cursor of datapoints specified by a series filter. - * - * This endpoint allows one to request multiple series and apply an aggregation function. - * - * @param filter The series filter - * @param interval An interval of time for the query (start/end datetimes) - * @param timezone The time zone for the returned datapoints. - * @param aggregation The aggregation for the read query. This is required. - * @param rollup The rollup for the read query. This can be null. - * @param interpolation The interpolation for the read query. This can be null. - * @return A Cursor of DataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Aggregation - * @see Cursor - * @see Filter - * @see Interpolation - * @see Rollup - * @since 1.0.0 - */ - public Cursor readDataPoints(Filter filter, Interval interval, DateTimeZone timezone, Aggregation aggregation, Rollup rollup, Interpolation interpolation) { - checkNotNull(filter); - checkNotNull(interval); - checkNotNull(aggregation); - checkNotNull(timezone); - - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/segment/", API_VERSION)); - addFilterToURI(builder, filter); - addInterpolationToURI(builder, interpolation); - addIntervalToURI(builder, interval); - addAggregationToURI(builder, aggregation); - addRollupToURI(builder, rollup); - addTimeZoneToURI(builder, timezone); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = String.format("Could not build URI with inputs: filter: %s, interval: %s, aggregation: %s, rollup: %s, timezone: %s", filter, interval, aggregation, rollup, timezone); - throw new IllegalArgumentException(message, e); - } - - Cursor cursor = new DataPointCursor(uri, this); - return cursor; - } - - /** - * Returns a cursor of multi-datapoints specified by a series filter. - * - *

This endpoint allows one to request datapoints for multiple series in one call. - * The system default timezone is used for the returned DateTimes. - * - * @param filter The series filter - * @param interval An interval of time for the query (start/end datetimes) - * @return A Cursor of MultiDataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Cursor - * @see Filter - * @see MultiDataPoint - * @since 1.1.0 - */ - public Cursor readMultiDataPoints(Filter filter, Interval interval) { - return readMultiDataPoints(filter, interval, DateTimeZone.getDefault(), null, null); - } - - /** - * Returns a cursor of multi-datapoints specified by a series filter. - * - *

This endpoint allows one to request datapoints for multiple series in one call. - * The system default timezone is used for the returned DateTimes. - * - * @param filter The series filter - * @param interval An interval of time for the query (start/end datetimes) - * @param rollup The rollup for the read query. This can be null. - * @return A Cursor of MultiDataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Cursor - * @see Filter - * @see MultiDataPoint - * @see Rollup - * @since 1.1.0 - */ - public Cursor readMultiDataPoints(Filter filter, Interval interval, Rollup rollup) { - return readMultiDataPoints(filter, interval, DateTimeZone.getDefault(), rollup, null); - } - - /** - * Returns a cursor of multi-datapoints specified by a series filter. - * - * This endpoint allows one to request datapoints for multiple series in one call. - * - * @param filter The series filter - * @param interval An interval of time for the query (start/end datetimes) - * @param timezone The time zone for the returned datapoints. - * @return A Cursor of MultiDataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Cursor - * @see Filter - * @see MultiDataPoint - * @see Rollup - * @since 1.1.0 - */ - public Cursor readMultiDataPoints(Filter filter, Interval interval, DateTimeZone timezone) { - return readMultiDataPoints(filter, interval, timezone, null, null); - } - - /** - * Returns a cursor of multi-datapoints specified by a series filter. - * - * This endpoint allows one to request datapoints for multiple series in one call. - * - * @param filter The series filter - * @param interval An interval of time for the query (start/end datetimes) - * @param timezone The time zone for the returned datapoints. - * @param rollup The rollup for the read query. This can be null. - * @param interpolation The interpolation for the read query. This can be null. - * @return A Cursor of MultiDataPoints. The cursor.iterator().next() may throw a {@link TempoDBException} if an error occurs while making a request. - * - * @see Cursor - * @see Filter - * @see Interpolation - * @see MultiDataPoint - * @see Rollup - * @since 1.1.0 - */ - public Cursor readMultiDataPoints(Filter filter, Interval interval, DateTimeZone timezone, Rollup rollup, Interpolation interpolation) { - checkNotNull(filter); - checkNotNull(interval); - checkNotNull(timezone); - - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/multi/", API_VERSION)); - addFilterToURI(builder, filter); - addInterpolationToURI(builder, interpolation); - addIntervalToURI(builder, interval); - addRollupToURI(builder, rollup); - addTimeZoneToURI(builder, timezone); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = String.format("Could not build URI with inputs: filter: %s, interval: %s, rollup: %s, timezone: %s", filter, interval, rollup, timezone); - throw new IllegalArgumentException(message, e); - } - - Cursor cursor = new MultiDataPointCursor(uri, this); - return cursor; - } - - /** - * Updates all of a Series metadata - * - * @param series The series to update - * @return The updated Series - * - * @see Series - * @since 1.0.0 - */ - public Result updateSeries(Series series) { - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/", API_VERSION, urlencode(series.getKey()))); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = "Could not build URI"; - throw new IllegalArgumentException(message, e); - } - - Result result = null; - String body = null; - try { - body = Json.dumps(series); - } catch (JsonProcessingException e) { - String message = "Error serializing the body of the request. More detail: " + e.getMessage(); - result = new Result(null, GENERIC_ERROR_CODE, message); - return result; - } - - HttpRequest request = buildRequest(uri.toString(), HttpMethod.PUT, body); - result = execute(request, Series.class); - return result; - } - - /** - * Writes datapoints to single Series. - * - * @param series The series to write to. - * @param data A list of datapoints - * @return {@link Void} - * - * @see DataPoint - * @see Void - * @since 1.0.0 - */ - public Result writeDataPoints(Series series, List data) { - checkNotNull(series); - checkNotNull(data); - - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/series/key/%s/data/", API_VERSION, urlencode(series.getKey()))); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = String.format("Could not build URI with inputs: key: %s", series.getKey()); - throw new IllegalArgumentException(message, e); - } - - Result result = null; - String body = null; - try{ - body = Json.dumps(data); - } catch (JsonProcessingException e) { - String message = "Error serializing the body of the request. More detail: " + e.getMessage(); - result = new Result(null, GENERIC_ERROR_CODE, message); - return result; - } - - HttpRequest request = buildRequest(uri.toString(), HttpMethod.POST, body); - result = execute(request, Void.class); - return result; - } - - /** - * Writes datapoints to multiple Series. - * - *

This request can partially succeed. You should check the {@link Result#getState()} to check if the request was - * successful. If the request was partially successful, the result's {@link MultiStatus} can be inspected to determine - * what failed. - * - * @param request A WriteRequest for the DataPoints to write. - * @return {@link Void} - * - * @see MultiDataPoint - * @see MultiStatus - * @since 1.0.0 - */ - public Result writeDataPoints(WriteRequest request) { - checkNotNull(request); - - URI uri = null; - try { - URIBuilder builder = new URIBuilder(String.format("/%s/multi/", API_VERSION)); - uri = builder.build(); - } catch (URISyntaxException e) { - String message = "Could not build URI."; - throw new IllegalArgumentException(message, e); - } - - Result result = null; - String body = null; - try { - body = Json.dumps(request); - } catch (JsonProcessingException e) { - String message = "Error serializing the body of the request. More detail: " + e.getMessage(); - result = new Result(null, GENERIC_ERROR_CODE, message); - return result; - } - - HttpRequest httpRequest = buildRequest(uri.toString(), HttpMethod.POST, body); - result = execute(httpRequest, Void.class); - return result; - } - - private void addAggregationToURI(URIBuilder builder, Aggregation aggregation) { - if(aggregation != null) { - builder.addParameter("aggregation.fold", aggregation.getFold().toString().toLowerCase()); - } - } - - private void addDirectionToURI(URIBuilder builder, Direction direction) { - if(direction != null) { - builder.addParameter("direction", direction.toString().toLowerCase()); - } - } - - private void addFilterToURI(URIBuilder builder, Filter filter) { - if(filter != null) { - for(String key : filter.getKeys()) { - builder.addParameter("key", key); - } - - for(String tag : filter.getTags()) { - builder.addParameter("tag", tag); - } - - for(Map.Entry attribute : filter.getAttributes().entrySet()) { - builder.addParameter(String.format("attr[%s]", attribute.getKey()), attribute.getValue()); - } - } - } - - private void addInterpolationToURI(URIBuilder builder, Interpolation interpolation) { - if(interpolation != null) { - builder.addParameter("interpolation.period", interpolation.getPeriod().toString()); - builder.addParameter("interpolation.function", interpolation.getFunction().toString().toLowerCase()); - } - } - - private void addIntervalToURI(URIBuilder builder, Interval interval) { - if(interval != null) { - builder.addParameter("start", interval.getStart().toString(iso8601)); - builder.addParameter("end", interval.getEnd().toString(iso8601)); - } - } - - private void addMultiRollupToURI(URIBuilder builder, MultiRollup rollup) { - if(rollup != null) { - builder.addParameter("rollup.period", rollup.getPeriod().toString()); - for(Fold fold : rollup.getFolds()) { - builder.addParameter("rollup.fold", fold.toString().toLowerCase()); - } - } - } - - private void addPredicateToURI(URIBuilder builder, Predicate predicate) { - if(predicate != null) { - builder.addParameter("predicate.period", predicate.getPeriod().toString()); - builder.addParameter("predicate.function", predicate.getFunction().toLowerCase()); - } - } - - private void addRollupToURI(URIBuilder builder, Rollup rollup) { - if(rollup != null) { - builder.addParameter("rollup.period", rollup.getPeriod().toString()); - builder.addParameter("rollup.fold", rollup.getFold().toString().toLowerCase()); - } - } - - private void addTimestampToURI(URIBuilder builder, DateTime timestamp) { - if(timestamp != null) { - builder.addParameter("ts", timestamp.toString(iso8601)); - } - } - - private void addTimeZoneToURI(URIBuilder builder, DateTimeZone timezone) { - if(timezone != null) { - builder.addParameter("tz", timezone.toString()); - } - } - - private String urlencode(String key) { - String encoded; - try { - encoded = URLEncoder.encode(key, "utf-8").replaceAll("\\+", "%20"); - } catch (UnsupportedEncodingException e) { - encoded = key; - } - return encoded; - } - - HttpRequest buildRequest(String uri) { - return buildRequest(uri, HttpMethod.GET, null); - } - - HttpRequest buildRequest(String uri, HttpMethod method) { - return buildRequest(uri, method, null); - } - - HttpRequest buildRequest(String uri, HttpMethod method, String body) { - HttpRequest request = null; - - switch(method) { - case POST: - HttpPost post = new HttpPost(uri); - if(body != null) { - post.setEntity(new StringEntity(body, DEFAULT_CHARSET)); - } - request = post; - break; - case PUT: - HttpPut put = new HttpPut(uri); - if(body != null) { - put.setEntity(new StringEntity(body, DEFAULT_CHARSET)); - } - request = put; - break; - case DELETE: - request = new HttpDelete(uri); - break; - case GET: - default: - request = new HttpGet(uri); - break; - } - - return request; - } - - HttpResponse execute(HttpRequest request) throws IOException { - HttpClient client = getHttpClient(); - HttpContext context = getContext(); - HttpHost target = getTarget(); - HttpResponse response = client.execute(target, request, context); - return response; - } - - Result execute(HttpRequest request, Class klass) { - Result result = null; - try { - HttpResponse response = execute(request); - result = new Result(response, klass); - } catch (IOException e) { - result = new Result(null, GENERIC_ERROR_CODE, e.getMessage()); - } - return result; - } - - private synchronized HttpClient getHttpClient() { - if(client == null) { - HttpParams httpParams = new BasicHttpParams(); - HttpConnectionParams.setConnectionTimeout(httpParams, DEFAULT_TIMEOUT_MILLIS); - HttpConnectionParams.setSoTimeout(httpParams, DEFAULT_TIMEOUT_MILLIS); - HttpProtocolParams.setUserAgent(httpParams, String.format("tempodb-java/%s", getVersion())); - - DefaultHttpClient defaultClient = new DefaultHttpClient(new PoolingClientConnectionManager(), httpParams); - defaultClient.getCredentialsProvider().setCredentials( - new AuthScope(getTarget()), - new UsernamePasswordCredentials(credentials.getKey(), credentials.getSecret())); - - // Add gzip header to all requests - defaultClient.addRequestInterceptor(new HttpRequestInterceptor() { - public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException { - if (!request.containsHeader("Accept-Encoding")) { - request.addHeader("Accept-Encoding", "gzip"); - } - } - }); - - defaultClient.addResponseInterceptor(new HttpResponseInterceptor() { - public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException { - HttpEntity entity = response.getEntity(); - if (entity != null) { - Header ceheader = entity.getContentEncoding(); - if (ceheader != null) { - HeaderElement[] codecs = ceheader.getElements(); - for (int i = 0; i < codecs.length; i++) { - if (codecs[i].getName().equalsIgnoreCase("gzip")) { - response.setEntity(new GzipDecompressingEntity(response.getEntity())); - return; - } - } - } - } - } - }); - - defaultClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() { - public long getKeepAliveDuration(HttpResponse response, HttpContext context) { - HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE)); - - while(it.hasNext()) { - HeaderElement he = it.nextElement(); - String param = he.getName(); - String value = he.getValue(); - if(value != null && param.equalsIgnoreCase("timeout")) { - try { - return Long.parseLong(value) * 1000; - } catch (NumberFormatException ignore) { - } - } - } - return DEFAULT_KEEPALIVE_TIMEOUT_MILLIS; - } - }); - - client = defaultClient; - } - return client; - } - - synchronized Client setHttpClient(HttpClient httpClient) { - this.client = httpClient; - return this; - } - - private HttpContext getContext() { - HttpHost targetHost = getTarget(); - - // Create AuthCache instance - AuthCache authCache = new BasicAuthCache(); - // Generate BASIC scheme object and add it to the local - // auth cache - BasicScheme basicAuth = new BasicScheme(); - authCache.put(targetHost, basicAuth); - - // Add AuthCache to the execution context - BasicHttpContext localcontext = new BasicHttpContext(); - localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache); - return localcontext; - } - - private HttpHost getTarget() { - if(target == null) { - target = new HttpHost(host.getHostName(), host.getPort(), scheme); - } - return target; - } - - private String getVersion() { - return VERSION; - } -} diff --git a/src/main/java/com/tempodb/ClientBuilder.java b/src/main/java/com/tempodb/ClientBuilder.java deleted file mode 100644 index 3f5c54b..0000000 --- a/src/main/java/com/tempodb/ClientBuilder.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.tempodb; - -import java.net.InetSocketAddress; - -import static com.tempodb.util.Preconditions.*; - -/** - * A helper class to create Client objects. - * - *

The database and credentials must be specified. All other parameters are optional. - *

The following default values are used: - *

    - *
  • host - new InetSocketAddress("api.tempo-db.com", 443)
  • - *
  • scheme - "https"
  • - *
- *

This class uses the fluent style. A client can be created by chaining calls: - *

- *    import java.net.InetSocketAddress;
- *
- *    Database database = new Database("id");
- *    Credentials credentials = new Credentials("api-key", "api-secret");
- *    InetSocketAddress host = new InetSocketAddress("api.tempo-db.com", 443);
- *
- *    Client client = new ClientBuilder()
- *                      .database(database)
- *                      .credentials(credentials)
- *                      .host(host)
- *                      .scheme("https")
- *                      .build();
- *  
- * - * @since 1.0.0 - */ -public class ClientBuilder { - - private Database database; - private Credentials credentials; - private InetSocketAddress host; - private String scheme; - - private static final InetSocketAddress DEFAULT_HOST = new InetSocketAddress("api.tempo-db.com", 443); - private static final String DEFAULT_SCHEME = "https"; - - /** - * Base constructor. - * @since 1.0.0 - */ - public ClientBuilder() { - this.database = null; - this.credentials = null; - this.host = DEFAULT_HOST; - this.scheme = DEFAULT_SCHEME; - } - - /** - * Sets the database to connect to. This is required. - * @param database Database to connect to - * @since 1.0.0 - */ - public ClientBuilder database(Database database) { - this.database = checkNotNull(database); - return this; - } - - /** - * Sets the credentials to use for the specified database. - * This is required. - * @param credentials Database credentials - * @since 1.0.0 - */ - public ClientBuilder credentials(Credentials credentials) { - this.credentials = checkNotNull(credentials); - return this; - } - - /** - * Sets the host to connect to. Defaults to api.tempo-db.com:443 - * @param host Host to connect to. - * @since 1.0.0 - */ - public ClientBuilder host(InetSocketAddress host) { - this.host = checkNotNull(host); - return this; - } - - /** - * Sets the scheme. Valid values are "http" and "https". Defaults to - * "https". - * @param scheme The scheme. - * @since 1.0.0 - */ - public ClientBuilder scheme(String scheme) { - this.scheme = checkNotNull(scheme); - return this; - } - - /** - * Creates the client object using the specified parameters. - * @return The build client - * @since 1.0.0 - */ - public Client build() { - validate(); - Client client = new Client(database, credentials, host, scheme); - return client; - } - - private void validate() { - checkNotNull(database, "Database must not be null."); - checkNotNull(credentials, "Credentials must not be null."); - } -} diff --git a/src/main/java/com/tempodb/Credentials.java b/src/main/java/com/tempodb/Credentials.java deleted file mode 100644 index 3f0a758..0000000 --- a/src/main/java/com/tempodb/Credentials.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.tempodb; - -import java.io.Serializable; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; - -import static com.tempodb.util.Preconditions.*; - - -/** - * Api Credentials - * - * @since 1.0.0 - */ -public class Credentials implements Serializable { - private String key; - private String secret; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - public Credentials() { - this("", ""); - } - - public Credentials(String key, String secret) { - this.key = checkNotNull(key); - this.secret = checkNotNull(secret); - } - - /** - * Returns the key for these Credentials. - * @return Credentials key. - * @since 1.0.0 - */ - public String getKey() { return key; } - - /** - * Sets the key for these Credentials. - * @param key Credentials key. - * @since 1.0.0 - */ - public void setKey(String key) { this.key = checkNotNull(key); } - - /** - * Returns the secret for these Credentials. - * @return Credentials secret. - * @since 1.0.0 - */ - public String getSecret() { return secret; } - - /** - * Sets the secret for these Credentials. - * @param secret Credentials secret. - * @since 1.0.0 - */ - public void setSecret(String secret) { this.secret = checkNotNull(secret); } - - @Override - public String toString() { - return String.format("Credentials(key=%s, secret=%s)", key, secret); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(191, 193) - .append(key) - .append(secret) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof Credentials)) return false; - - Credentials rhs = (Credentials)obj; - return new EqualsBuilder() - .append(key, rhs.key) - .append(secret, rhs.secret) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/Cursor.java b/src/main/java/com/tempodb/Cursor.java deleted file mode 100644 index d21f216..0000000 --- a/src/main/java/com/tempodb/Cursor.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.tempodb; - -/** - * An interface representing an {@link Iterable} of some other model object. - * - * This is usually used for returning a sequence of {@link DataPoint}'s or {@link Series}. - * Note that the returned iterator is not cached, so iterating multiple times requires a - * network call. - * - *

This iterator will throw a {@link TempoDBException} if an error occurs while retrieving the - * data. - * @since 1.0.0 - */ -public interface Cursor extends Iterable { } diff --git a/src/main/java/com/tempodb/DataPoint.java b/src/main/java/com/tempodb/DataPoint.java deleted file mode 100644 index 935e443..0000000 --- a/src/main/java/com/tempodb/DataPoint.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.tempodb; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.joda.time.DateTime; - -import static com.tempodb.util.Preconditions.*; - -/** - * A timestamp/value pair. - * @since 1.0.0 - */ -public class DataPoint implements Serializable { - - private DateTime timestamp; - private Number value; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - public DataPoint() { - this(new DateTime(), 0.0); - } - - /** - * Base constructor - * @param timestamp The timestamp of the datapoint - * @param value The numeric value of the datapoint - * @since 1.0.0 - */ - public DataPoint(@JsonProperty("t") DateTime timestamp, @JsonProperty("v") Number value) { - this.timestamp = checkNotNull(timestamp); - this.value = checkNotNull(value); - } - - /** - * Returns the timestamp of this DataPoint. - * @return the timestamp - * @since 1.0.0 - */ - @JsonProperty("t") - public DateTime getTimestamp() { return timestamp; } - - /** - * Sets the timestamp of this datapoint. - * @param timestamp The timestamp of this DataPoint - * @since 1.0.0 - */ - public void setTimestamp(DateTime timestamp) { this.timestamp = checkNotNull(timestamp); } - - /** - * Returns the value of this DataPoint. - * @return the value - * @since 1.0.0 - */ - @JsonProperty("v") - public Number getValue() { return value; } - - /** - * Sets the value of this DataPoint. - * @param value The value of this DataPoint - * @since 1.0.0 - */ - public void setValue(Number value) { this.value = checkNotNull(value); } - - @Override - public String toString() { - return String.format("DataPoint(timestamp=%s, value=%s)", timestamp.toString(), value.toString()); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(19, 31) - .append(timestamp) - .append(value) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof DataPoint)) return false; - - DataPoint rhs = (DataPoint)obj; - return new EqualsBuilder() - .append(timestamp, rhs.timestamp) - .append(value, rhs.value) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/DataPointCursor.java b/src/main/java/com/tempodb/DataPointCursor.java deleted file mode 100644 index 7f24833..0000000 --- a/src/main/java/com/tempodb/DataPointCursor.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.tempodb; - -import java.net.URI; -import java.util.Iterator; - -import org.apache.http.HttpRequest; - -import static com.tempodb.util.Preconditions.*; - - -class DataPointCursor implements Cursor { - private final URI uri; - private final Client client; - - public DataPointCursor(URI uri, Client client) { - this.uri = checkNotNull(uri); - this.client = checkNotNull(client); - } - - public Iterator iterator() { - HttpRequest request = client.buildRequest(uri.toString()); - Result result = client.execute(request, DataPointSegment.class); - - Iterator iterator = null; - if(result.getState() == State.SUCCESS) { - @SuppressWarnings("unchecked") // This cast is always ok - SegmentIterator> segments = new SegmentIterator(client, result.getValue(), DataPointSegment.class); - iterator = new SegmentInnerIterator(segments); - } else { - throw new TempoDBException(result.getMessage(), result.getCode()); - } - return iterator; - } -} diff --git a/src/main/java/com/tempodb/DataPointFound.java b/src/main/java/com/tempodb/DataPointFound.java deleted file mode 100644 index 89a96f9..0000000 --- a/src/main/java/com/tempodb/DataPointFound.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.tempodb; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.joda.time.DateTime; -import org.joda.time.Interval; - -import static com.tempodb.util.Preconditions.*; - -/** - * A timestamp/value pair. - * @since 1.1.0 - */ -public class DataPointFound implements Serializable { - - private Interval interval; - private DataPoint datapoint; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - public DataPointFound() { - this(new Interval(new DateTime(), new DateTime()), new DataPoint(new DateTime(), 0.0)); - } - - /** - * Base constructor - * @param interval The interval of the found range - * @param datapoint The found datapoint (may be null) for some predicates - * @since 1.1.0 - */ - public DataPointFound(@JsonProperty("interval") Interval interval, @JsonProperty("found") DataPoint datapoint) { - this.interval = checkNotNull(interval); - this.datapoint = checkNotNull(datapoint); - } - - /** - * Returns the interval of this DataPointFound. - * @return the interval - * @since 1.1.0 - */ - @JsonProperty("interval") - public Interval getInterval() { return interval; } - - /** - * Sets the interval of this DataPointFound. - * @param interval The interval of this DataPointFound - * @since 1.1.0 - */ - public void setInterval(Interval interval) { this.interval = checkNotNull(interval); } - - /** - * Returns the datapoint of this DataPointFound. - * @return the datapoint - * @since 1.1.0 - */ - @JsonProperty("found") - public DataPoint getDataPoint() { return datapoint; } - - /** - * Sets the datapoint of this DataPointFound. - * @param datapoint The datapoint of this DataPointFound - * @since 1.1.0 - */ - public void setDataPoint(DataPoint datapoint) { this.datapoint = checkNotNull(datapoint); } - - @Override - public String toString() { - return String.format("DataPointFound(interval=%s, datapoint=%s)", interval.toString(), datapoint.toString()); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(19, 31) - .append(interval) - .append(datapoint) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof DataPointFound)) return false; - - DataPointFound rhs = (DataPointFound)obj; - return new EqualsBuilder() - .append(interval, rhs.interval) - .append(datapoint, rhs.datapoint) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/DataPointFoundCursor.java b/src/main/java/com/tempodb/DataPointFoundCursor.java deleted file mode 100644 index 7d70d91..0000000 --- a/src/main/java/com/tempodb/DataPointFoundCursor.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.tempodb; - -import java.net.URI; -import java.util.Iterator; - -import org.apache.http.HttpRequest; - -import static com.tempodb.util.Preconditions.*; - - -class DataPointFoundCursor implements Cursor { - private final URI uri; - private final Client client; - - public DataPointFoundCursor(URI uri, Client client) { - this.uri = checkNotNull(uri); - this.client = checkNotNull(client); - } - - public Iterator iterator() { - HttpRequest request = client.buildRequest(uri.toString()); - Result result = client.execute(request, DataPointFoundSegment.class); - - Iterator iterator = null; - if(result.getState() == State.SUCCESS) { - @SuppressWarnings("unchecked") // This cast is always ok - SegmentIterator> segments = new SegmentIterator(client, result.getValue(), DataPointFoundSegment.class); - iterator = new SegmentInnerIterator(segments); - } else { - throw new TempoDBException(result.getMessage(), result.getCode()); - } - return iterator; - } -} diff --git a/src/main/java/com/tempodb/DataPointFoundSegment.java b/src/main/java/com/tempodb/DataPointFoundSegment.java deleted file mode 100644 index 6b3fd45..0000000 --- a/src/main/java/com/tempodb/DataPointFoundSegment.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; -import org.joda.time.DateTimeZone; - -import com.tempodb.http.PageLinks; -import com.tempodb.json.Json; -import static com.tempodb.util.Preconditions.*; - - -public class DataPointFoundSegment extends Segment { - - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - - private DateTimeZone timezone; - private Predicate predicate; - - public DataPointFoundSegment() { - this(new ArrayList(), "", DateTimeZone.UTC, null); - } - - @JsonCreator - public DataPointFoundSegment(@JsonProperty("data") List data, @JsonProperty("tz") DateTimeZone timezone, @JsonProperty("predicate") Predicate predicate) { - this(data, null, timezone, predicate); - } - - public DataPointFoundSegment(List data, String next, DateTimeZone timezone, Predicate predicate) { - super(data, next); - this.timezone = checkNotNull(timezone); - this.predicate = predicate; - } - - @JsonProperty("tz") - public DateTimeZone getTimeZone() { return this.timezone; } - public void setTimeZone(DateTimeZone timezone) { this.timezone = checkNotNull(timezone); } - - public Predicate getPredicate() { return this.predicate; } - public void setPredicate(Predicate predicate) { this.predicate = predicate; } - - static DataPointFoundSegment make(HttpResponse response) throws IOException { - String body = EntityUtils.toString(response.getEntity(), DEFAULT_CHARSET); - DataPointFoundSegment segment = Json.loads(body, DataPointFoundSegment.class); - PageLinks links = new PageLinks(response); - segment.next = links.getNext(); - return segment; - } - - @Override - public String toString() { - return String.format("DataPointFoundSegment(data=%s, next=%s, timezone=%s, predicate=%s", data, next, timezone, predicate); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(11, 43) - .append(data) - .append(next) - .append(timezone) - .append(predicate) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof DataPointFoundSegment)) return false; - - DataPointFoundSegment rhs = (DataPointFoundSegment)obj; - return new EqualsBuilder() - .append(data, rhs.data) - .append(next, rhs.next) - .append(timezone, rhs.timezone) - .append(predicate, rhs.predicate) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/DataPointSegment.java b/src/main/java/com/tempodb/DataPointSegment.java deleted file mode 100644 index 22821e7..0000000 --- a/src/main/java/com/tempodb/DataPointSegment.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; -import org.joda.time.DateTimeZone; - -import com.tempodb.http.PageLinks; -import com.tempodb.json.Json; -import static com.tempodb.util.Preconditions.*; - - -public class DataPointSegment extends Segment { - - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - - private DateTimeZone timezone; - private Rollup rollup; - - public DataPointSegment() { - this(new ArrayList(), "", DateTimeZone.UTC, null); - } - - @JsonCreator - public DataPointSegment(@JsonProperty("data") List data, @JsonProperty("tz") DateTimeZone timezone, @JsonProperty("rollup") Rollup rollup) { - this(data, null, timezone, rollup); - } - - public DataPointSegment(List data, String next, DateTimeZone timezone, Rollup rollup) { - super(data, next); - this.timezone = checkNotNull(timezone); - this.rollup = rollup; - } - - @JsonProperty("tz") - public DateTimeZone getTimeZone() { return this.timezone; } - public void setTimeZone(DateTimeZone timezone) { this.timezone = checkNotNull(timezone); } - - public Rollup getRollup() { return this.rollup; } - public void setRollup(Rollup rollup) { this.rollup = rollup; } - - static DataPointSegment make(HttpResponse response) throws IOException { - String body = EntityUtils.toString(response.getEntity(), DEFAULT_CHARSET); - DataPointSegment segment = Json.loads(body, DataPointSegment.class); - PageLinks links = new PageLinks(response); - segment.next = links.getNext(); - return segment; - } - - @Override - public String toString() { - return String.format("DataPointSegment(data=%s, next=%s, timezone=%s, rollup=%s", data, next, timezone, rollup); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(11, 43) - .append(data) - .append(next) - .append(timezone) - .append(rollup) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof DataPointSegment)) return false; - - DataPointSegment rhs = (DataPointSegment)obj; - return new EqualsBuilder() - .append(data, rhs.data) - .append(next, rhs.next) - .append(timezone, rhs.timezone) - .append(rollup, rhs.rollup) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/Database.java b/src/main/java/com/tempodb/Database.java deleted file mode 100644 index b3d6eb5..0000000 --- a/src/main/java/com/tempodb/Database.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.tempodb; - -import java.io.Serializable; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; - -import static com.tempodb.util.Preconditions.*; - - -/** - * A Database representation. - * - * @since 1.0.0 - */ -public class Database implements Serializable { - private String id; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - public Database() { - this(""); - } - - public Database(String id) { - this.id = checkNotNull(id); - } - - /** - * Returns the id for the Database. - * @return Database id.. - * @since 1.0.0 - */ - public String getId() { return id; } - - /** - * Sets the id for the Database. - * @param id Database id.. - * @since 1.0.0 - */ - public void setId(String id) { this.id = checkNotNull(id); } - - @Override - public String toString() { - return String.format("Database(id=%s)", id); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(241, 251) - .append(id) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof Database)) return false; - - Database rhs = (Database)obj; - return new EqualsBuilder() - .append(id, rhs.id) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/DeleteSummary.java b/src/main/java/com/tempodb/DeleteSummary.java deleted file mode 100644 index 972d163..0000000 --- a/src/main/java/com/tempodb/DeleteSummary.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.io.Serializable; -import java.nio.charset.Charset; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; - -import com.tempodb.json.Json; -import static com.tempodb.util.Preconditions.*; - - -/** - * Information about a delete series operation. - * @since 1.0.0 - */ -public class DeleteSummary implements Serializable { - - private int deleted; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - - public DeleteSummary() { - this(0); - } - - /** - * Base constructor. - * @param deleted The number of Series deleted. - * @see Series - * @since 1.0.0 - */ - public DeleteSummary(int deleted) { - this.deleted = deleted; - } - - /** - * Returns the number of Series deleted. - * @return Number of Series deleted. - * @see Series - * @since 1.0.0 - */ - public int getDeleted() { return deleted; } - - /** - * Sets the number of Series deleted. - * @param deleted The number of Series deleted. - * @see Series - * @since 1.0.0 - */ - public void setDeleted(int deleted) { this.deleted = deleted; } - - static DeleteSummary make(HttpResponse response) throws IOException { - String body = EntityUtils.toString(response.getEntity(), DEFAULT_CHARSET); - DeleteSummary summary = Json.loads(body, DeleteSummary.class); - return summary; - } - - @Override - public String toString() { - return String.format("DeleteSummary(deleted=%d)", deleted); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(179, 181) - .append(deleted) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof DeleteSummary)) return false; - - DeleteSummary rhs = (DeleteSummary)obj; - return new EqualsBuilder() - .append(deleted, rhs.deleted) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/Direction.java b/src/main/java/com/tempodb/Direction.java deleted file mode 100644 index f6919bd..0000000 --- a/src/main/java/com/tempodb/Direction.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.tempodb; - - -/** - * Direction to search for Single Value calls. - * @since 1.1.0 - */ -public enum Direction { - /** - * Before the timestamp - * @since 1.1.0 - */ - BEFORE, - - /** - * After the timestamp - * @since 1.1.0 - */ - AFTER, - - /** - * Nearest the timestamp - * @since 1.1.0 - */ - NEAREST, - - /** - * Exact timestamp match - * @since 1.1.0 - */ - EXACT -} diff --git a/src/main/java/com/tempodb/Filter.java b/src/main/java/com/tempodb/Filter.java deleted file mode 100644 index 96a54a6..0000000 --- a/src/main/java/com/tempodb/Filter.java +++ /dev/null @@ -1,187 +0,0 @@ -package com.tempodb; - -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; - - -/** - * Represents a filter on the set of Series. This is used to query a set of series with specific - * properties. A filter can include keys, tags and attributes. An empty filter is created - * and filter predicates are added. For example a filter to return series with keys myagley-1 and - * myagley-2 looks like this: - * - *

- *  Filter filter = new Filter();
- *  filter.addKey("myagley-1");
- *  filter.addKey("myagley-1");
- *  
- * @since 1.0.0 - */ -public class Filter { - private final Set keys = new LinkedHashSet(); - private final Set tags = new LinkedHashSet(); - private final Map attributes = new HashMap(); - - /** - * Returns the keys to filter on. - * @return A set of keys. - * @since 1.0.0 - */ - public Set getKeys() { return keys; } - - /** - * Returns the tags to filter on. - * @return A set of tags. - * @since 1.0.0 - */ - public Set getTags() { return tags; } - - /** - * Returns the attributes to filter on. - * @return A map of attributes. - * @since 1.0.0 - */ - public Map getAttributes() { return attributes; } - - /** - * Adds a key to the filter. - * - * @param key The key to add. - * @return This filter - * @since 1.0.0 - */ - public synchronized Filter addKey(String key) { - keys.add(key); - return this; - } - - /** - * Adds a list of keys to the filter. - * - * @param keys The keys to add. - * @return This filter - * @since 1.0.0 - */ - public synchronized Filter addKeys(String... keys) { - for(String key : keys) { - this.keys.add(key); - } - return this; - } - - /** - * Adds a set of keys to the filter. - * - * @param keys The set of keys to add. - * @return This filter - * @since 1.0.0 - */ - public synchronized Filter addKeys(Set keys) { - for(String key : keys) { - this.keys.add(key); - } - return this; - } - - /** - * Adds a tag to the filter. - * - * @param tag The tag to add. - * @return This filter - * @since 1.0.0 - */ - public synchronized Filter addTag(String tag) { - tags.add(tag); - return this; - } - - /** - * Adds a list of tags to the filter. - * - * @param tags The tags to add. - * @return This filter - * @since 1.0.0 - */ - public synchronized Filter addTags(String... tags) { - for(String tag : tags) { - this.tags.add(tag); - } - return this; - } - - /** - * Adds a set of tags to the filter. - * - * @param tags The set of tags to add. - * @return This filter - * @since 1.0.0 - */ - public synchronized Filter addTags(Set tags) { - for(String tag : tags) { - this.tags.add(tag); - } - return this; - } - - /** - * Adds an attribute to the filter. - * - * @param key The attribute key. - * @param value The attribute value. - * @return This filter - * @since 1.0.0 - */ - public synchronized Filter addAttribute(String key, String value) { - attributes.put(key, value); - return this; - } - - /** - * Adds a map of attributes to the filter. - * - * @param attributes The map of attributes to add. - * @return This filter - * @since 1.0.0 - */ - public synchronized Filter addAttributes(Map attributes) { - for(Map.Entry pair : attributes.entrySet()) { - String key = pair.getKey(); - String value = pair.getValue(); - this.attributes.put(key, value); - } - return this; - } - - @Override - public String toString() { - return String.format("Filter(keys=%s, tags=%s, attributes=%s", keys, tags, attributes); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(113, 117) - .append(keys) - .append(tags) - .append(attributes) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof Filter)) return false; - - Filter rhs = (Filter)obj; - return new EqualsBuilder() - .append(keys, rhs.keys) - .append(tags, rhs.tags) - .append(attributes, rhs.attributes) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/Fold.java b/src/main/java/com/tempodb/Fold.java deleted file mode 100644 index 5e3359d..0000000 --- a/src/main/java/com/tempodb/Fold.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.tempodb; - - -/** - * Folding function for {@link Aggregation}'s and {@link Rollup}'s. - * @since 1.0.0 - */ -public enum Fold { - /** - * Sum of DataPoints - * @since 1.0.0 - */ - SUM, - - /** - * Multiplication of DataPoints - * @since 1.0.0 - */ - MULT, - - /** - * Arithmetic mean of DataPoints (average) - * @since 1.0.0 - */ - MEAN, - - /** - * Maximum of DataPoints - * @since 1.0.0 - */ - MAX, - - /** - * Minimum of DataPoints - * @since 1.0.0 - */ - MIN, - - /** - * Count of DataPoints - * @since 1.0.0 - */ - COUNT, - - /** - * Variance of DataPoints - * @since 1.0.0 - */ - VARIANCE, - - /** - * Standard deviation of DataPoints - * @since 1.0.0 - */ - STDDEV, - - /** - * Range of DataPoints (max - min) - * @since 1.0.0 - */ - RANGE, - - /** - * First DataPoint in interval (takes the left most DataPoint) - * @since 1.0.0 - */ - FIRST -} diff --git a/src/main/java/com/tempodb/Interpolation.java b/src/main/java/com/tempodb/Interpolation.java deleted file mode 100644 index 890ce69..0000000 --- a/src/main/java/com/tempodb/Interpolation.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.tempodb; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.joda.time.Period; - -import static com.tempodb.util.Preconditions.*; - - -/** - * The representation of an interpolation. - * - * A Interpolation allows you to specify a time period and function for a - * {@link DataPoint} query. An Interpolation will compute values for datapoints at - * regular intervals. This is useful for filling in missing data or aligning timestamps - * to a period. - *

Timestamps in the interpolated series are calculated as: - *

ts_n = interval.start + interpolation.period * n;
- * @see InterpolationFunction - * @since 1.1.0 - */ -public class Interpolation implements Serializable { - private Period period; - private InterpolationFunction function; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - public Interpolation() { - this(Period.minutes(1), InterpolationFunction.LINEAR); - } - - /** - * Base constructor - * - * @param period The interpolation period. - * @param function The interpolation function. - * @since 1.1.0 - */ - public Interpolation(@JsonProperty("period") Period period, @JsonProperty("function") InterpolationFunction function) { - this.period = checkNotNull(period); - this.function = checkNotNull(function); - } - - /** - * Returns the interpolation period. - * @return The interpolation period. - * @since 1.1.0 - */ - @JsonProperty("period") - public Period getPeriod() { return period; } - - /** - * Sets the interpolation period. - * @param period The period. - * @since 1.1.0 - */ - public void setPeriod(Period period) { this.period = checkNotNull(period); } - - /** - * Returns the interpolation function. - * @return The interpolation function. - * @since 1.1.0 - */ - @JsonProperty("function") - public InterpolationFunction getFunction() { return function; } - - /** Sets the interpolation function. - * @param function The interpolation function. - * @since 1.1.0 - */ - public void setFunction(InterpolationFunction function) { this.function = checkNotNull(function); } - - /** Creates a zero-order-hold interpolation instance - * @param period The interpolation period - * @since 1.1.0 - */ - public static Interpolation zoh(Period period) - { - return new Interpolation(period, InterpolationFunction.ZOH); - } - - /** Creates a linear interpolation instance - * @param period The interpolation period - * @since 1.1.0 - */ - public static Interpolation linear(Period period) - { - return new Interpolation(period, InterpolationFunction.LINEAR); - } - - @Override - public String toString() { - return String.format("Interpolation(period=%s,function=%s)", period.toString(), function.toString().toLowerCase()); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(13, 41) - .append(period) - .append(function) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof Interpolation)) return false; - - Interpolation rhs = (Interpolation)obj; - return new EqualsBuilder() - .append(period, rhs.period) - .append(function, rhs.function) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/InterpolationFunction.java b/src/main/java/com/tempodb/InterpolationFunction.java deleted file mode 100644 index 4b3fbd3..0000000 --- a/src/main/java/com/tempodb/InterpolationFunction.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.tempodb; - - -/** - * Interpolation function - * @since 1.1.0 - */ -public enum InterpolationFunction { - /** - * Zero-order-hold Interpolation - * @since 1.1.0 - */ - ZOH, - - /** - * Linear Interpolation - * @since 1.1.0 - */ - LINEAR -} diff --git a/src/main/java/com/tempodb/MultiDataPoint.java b/src/main/java/com/tempodb/MultiDataPoint.java deleted file mode 100644 index 35b9a54..0000000 --- a/src/main/java/com/tempodb/MultiDataPoint.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.tempodb; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.joda.time.DateTime; - -import static com.tempodb.util.Preconditions.*; - -/** - * A timestamp/multi-value pair. - * Represents a timestamp with multi-values. This is used for cursoring - * over multiple series at once or querying multiple rollups for a series. - * @since 1.1.0 - */ -public class MultiDataPoint implements Serializable { - - private DateTime timestamp; - private Map data; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - public MultiDataPoint() { - this(new DateTime(), new HashMap()); - } - - /** - * Base constructor - * @param timestamp The timestamp of the datapoint - * @param data Data for this timestamp - * @since 1.1.0 - */ - public MultiDataPoint(@JsonProperty("t") DateTime timestamp, @JsonProperty("v") Map data) { - this.timestamp = checkNotNull(timestamp); - this.data = checkNotNull(data); - } - - /** - * Returns the timestamp of this DataPoint. - * @return the timestamp - * @since 1.1.0 - */ - @JsonProperty("t") - public DateTime getTimestamp() { return timestamp; } - - /** - * Sets the timestamp of this datapoint. - * @param timestamp The timestamp of this DataPoint - * @since 1.1.0 - */ - public void setTimestamp(DateTime timestamp) { this.timestamp = checkNotNull(timestamp); } - - /** - * Returns the value of this DataPoint. - * @return the value - * @since 1.1.0 - */ - @JsonProperty("v") - public Map getData() { return data; } - - /** - * Sets the data of this DataPoint. - * @param data The map of data for this DataPoint - * @since 1.1.0 - */ - public void setData(Map data) { this.data = checkNotNull(data); } - - /** - * Gets the number for this key (series key or rollup fold). - * @param key The key to get - * @return the value - * @since 1.1.0 - */ - public Number get(String key) { return this.data.get(key); } - - @Override - public String toString() { - return String.format("MultiDataPoint(timestamp=%s, data=%s)", timestamp.toString(), data.toString()); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(19, 31) - .append(timestamp) - .append(data) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof MultiDataPoint)) return false; - - MultiDataPoint rhs = (MultiDataPoint)obj; - return new EqualsBuilder() - .append(timestamp, rhs.timestamp) - .append(data, rhs.data) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/MultiDataPointCursor.java b/src/main/java/com/tempodb/MultiDataPointCursor.java deleted file mode 100644 index 6b2929c..0000000 --- a/src/main/java/com/tempodb/MultiDataPointCursor.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.tempodb; - -import java.net.URI; -import java.util.Iterator; - -import org.apache.http.HttpRequest; - -import static com.tempodb.util.Preconditions.*; - - -class MultiDataPointCursor implements Cursor { - private final URI uri; - private final Client client; - - public MultiDataPointCursor(URI uri, Client client) { - this.uri = checkNotNull(uri); - this.client = checkNotNull(client); - } - - public Iterator iterator() { - HttpRequest request = client.buildRequest(uri.toString()); - Result result = client.execute(request, MultiDataPointSegment.class); - - Iterator iterator = null; - if(result.getState() == State.SUCCESS) { - @SuppressWarnings("unchecked") // This cast is always ok - SegmentIterator> segments = new SegmentIterator(client, result.getValue(), MultiDataPointSegment.class); - iterator = new SegmentInnerIterator(segments); - } else { - throw new TempoDBException(result.getMessage(), result.getCode()); - } - return iterator; - } -} diff --git a/src/main/java/com/tempodb/MultiDataPointSegment.java b/src/main/java/com/tempodb/MultiDataPointSegment.java deleted file mode 100644 index 0c86d8f..0000000 --- a/src/main/java/com/tempodb/MultiDataPointSegment.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; -import org.joda.time.DateTimeZone; - -import com.tempodb.http.PageLinks; -import com.tempodb.json.Json; -import static com.tempodb.util.Preconditions.*; - - -public class MultiDataPointSegment extends Segment { - - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - - private DateTimeZone timezone; - private Rollup rollup; - - public MultiDataPointSegment() { - this(new ArrayList(), "", DateTimeZone.UTC, null); - } - - @JsonCreator - public MultiDataPointSegment(@JsonProperty("data") List data, @JsonProperty("tz") DateTimeZone timezone, @JsonProperty("rollup") Rollup rollup) { - this(data, null, timezone, rollup); - } - - public MultiDataPointSegment(List data, String next, DateTimeZone timezone, Rollup rollup) { - super(data, next); - this.timezone = checkNotNull(timezone); - this.rollup = rollup; - } - - @JsonProperty("tz") - public DateTimeZone getTimeZone() { return this.timezone; } - public void setTimeZone(DateTimeZone timezone) { this.timezone = checkNotNull(timezone); } - - public Rollup getRollup() { return this.rollup; } - public void setRollup(Rollup rollup) { this.rollup = rollup; } - - static MultiDataPointSegment make(HttpResponse response) throws IOException { - String body = EntityUtils.toString(response.getEntity(), DEFAULT_CHARSET); - MultiDataPointSegment segment = Json.loads(body, MultiDataPointSegment.class); - PageLinks links = new PageLinks(response); - segment.next = links.getNext(); - return segment; - } - - @Override - public String toString() { - return String.format("MultiDataPointSegment(data=%s, next=%s, timezone=%s, rollup=%s", data, next, timezone, rollup); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(11, 43) - .append(data) - .append(next) - .append(timezone) - .append(rollup) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof MultiDataPointSegment)) return false; - - MultiDataPointSegment rhs = (MultiDataPointSegment)obj; - return new EqualsBuilder() - .append(data, rhs.data) - .append(next, rhs.next) - .append(timezone, rhs.timezone) - .append(rollup, rhs.rollup) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/MultiRollup.java b/src/main/java/com/tempodb/MultiRollup.java deleted file mode 100644 index 1dec7f1..0000000 --- a/src/main/java/com/tempodb/MultiRollup.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.tempodb; - -import java.io.Serializable; -import java.util.Arrays; - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.joda.time.Period; - -import static com.tempodb.util.Preconditions.*; - - -/** - * The representation of a rollup with multiple folding function of a single {@link Series}. - * - * A MultiRollup allows you to specify a time period and an an array of folding functions for a - * {@link DataPoint} query. A MultiRollup represents a reduction in the amount of data - * returned to you. For instance, if you want to know the hourly average of a range - * of data, the MultiRollup is specified as: - * - *

- *  import org.joda.time.Period;
- *
- *  MultiRollup rollup = new MultiRollup(Period.hours(1), new Fold[] { Fold.SUM, Fold.MAX });
- *  
- * @see Fold - * @since 1.1.0 - */ -public class MultiRollup implements Serializable { - private Period period; - private Fold[] folds; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - public MultiRollup() { - this(Period.minutes(1), new Fold[] { Fold.SUM }); - } - - /** - * Base constructor - * - * @param period The rollup period. - * @param folds The rollup folding functions. - * @since 1.1.0 - */ - public MultiRollup(@JsonProperty("period") Period period, @JsonProperty("folds") Fold[] folds) { - this.period = checkNotNull(period); - this.folds = checkNotNull(folds); - } - - /** - * Returns the rollup period. - * @return The rollup period. - * @since 1.1.0 - */ - @JsonProperty("period") - public Period getPeriod() { return period; } - - /** - * Sets the rollup period. - * @param period The period. - * @since 1.1.0 - */ - public void setPeriod(Period period) { this.period = checkNotNull(period); } - - /** - * Returns the rollup folding functions. - * @return The rollup folding functions. - * @since 1.1.0 - */ - @JsonProperty("folds") - public Fold[] getFolds() { return Arrays.copyOf(folds, folds.length); } - - /** Sets the rollup folding functions. - * @param folds The rollup folding functions. - * @since 1.1.0 - */ - public void setFold(Fold[] folds) { this.folds = checkNotNull(folds); } - - @Override - public String toString() { - return String.format("MultiRollup(period=%s,folds=%s)", period.toString(), Arrays.toString(folds).toLowerCase()); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(13, 41) - .append(period) - .append(folds) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof MultiRollup)) return false; - - MultiRollup rhs = (MultiRollup)obj; - return new EqualsBuilder() - .append(period, rhs.period) - .append(folds, rhs.folds) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/MultiRollupDataPointCursor.java b/src/main/java/com/tempodb/MultiRollupDataPointCursor.java deleted file mode 100644 index a51b56b..0000000 --- a/src/main/java/com/tempodb/MultiRollupDataPointCursor.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.tempodb; - -import java.net.URI; -import java.util.Iterator; - -import org.apache.http.HttpRequest; - -import static com.tempodb.util.Preconditions.*; - - -class MultiRollupDataPointCursor implements Cursor { - private final URI uri; - private final Client client; - - public MultiRollupDataPointCursor(URI uri, Client client) { - this.uri = checkNotNull(uri); - this.client = checkNotNull(client); - } - - public Iterator iterator() { - HttpRequest request = client.buildRequest(uri.toString()); - Result result = client.execute(request, MultiRollupDataPointSegment.class); - - Iterator iterator = null; - if(result.getState() == State.SUCCESS) { - @SuppressWarnings("unchecked") // This cast is always ok - SegmentIterator> segments = new SegmentIterator(client, result.getValue(), MultiRollupDataPointSegment.class); - iterator = new SegmentInnerIterator(segments); - } else { - throw new TempoDBException(result.getMessage(), result.getCode()); - } - return iterator; - } -} diff --git a/src/main/java/com/tempodb/MultiRollupDataPointSegment.java b/src/main/java/com/tempodb/MultiRollupDataPointSegment.java deleted file mode 100644 index ddf0072..0000000 --- a/src/main/java/com/tempodb/MultiRollupDataPointSegment.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; -import org.joda.time.DateTimeZone; - -import com.tempodb.http.PageLinks; -import com.tempodb.json.Json; -import static com.tempodb.util.Preconditions.*; - - -public class MultiRollupDataPointSegment extends Segment { - - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - - private DateTimeZone timezone; - private MultiRollup rollup; - - public MultiRollupDataPointSegment() { - this(new ArrayList(), "", DateTimeZone.UTC, null); - } - - @JsonCreator - public MultiRollupDataPointSegment(@JsonProperty("data") List data, @JsonProperty("tz") DateTimeZone timezone, @JsonProperty("rollup") MultiRollup rollup) { - this(data, null, timezone, rollup); - } - - public MultiRollupDataPointSegment(List data, String next, DateTimeZone timezone, MultiRollup rollup) { - super(data, next); - this.timezone = checkNotNull(timezone); - this.rollup = rollup; - } - - @JsonProperty("tz") - public DateTimeZone getTimeZone() { return this.timezone; } - public void setTimeZone(DateTimeZone timezone) { this.timezone = checkNotNull(timezone); } - - public MultiRollup getRollup() { return this.rollup; } - public void setRollup(MultiRollup rollup) { this.rollup = rollup; } - - static MultiRollupDataPointSegment make(HttpResponse response) throws IOException { - String body = EntityUtils.toString(response.getEntity(), DEFAULT_CHARSET); - MultiRollupDataPointSegment segment = Json.loads(body, MultiRollupDataPointSegment.class); - PageLinks links = new PageLinks(response); - segment.next = links.getNext(); - return segment; - } - - @Override - public String toString() { - return String.format("MultiRollupDataPointSegment(data=%s, next=%s, timezone=%s, rollup=%s", data, next, timezone, rollup); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(11, 43) - .append(data) - .append(next) - .append(timezone) - .append(rollup) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof MultiRollupDataPointSegment)) return false; - - MultiRollupDataPointSegment rhs = (MultiRollupDataPointSegment)obj; - return new EqualsBuilder() - .append(data, rhs.data) - .append(next, rhs.next) - .append(timezone, rhs.timezone) - .append(rollup, rhs.rollup) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/MultiStatus.java b/src/main/java/com/tempodb/MultiStatus.java deleted file mode 100644 index 3852207..0000000 --- a/src/main/java/com/tempodb/MultiStatus.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.tempodb; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; - -import static com.tempodb.util.Preconditions.*; - - -/** - * Provides information about a partially successful API request. - * @since 1.0.0 - */ -public class MultiStatus implements Iterable, Serializable { - - private List statuses; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - public MultiStatus() { - this(new ArrayList()); - } - - /** - * Base constructor - * @param statuses List of {@link Status} objects. - * @since 1.0.0 - */ - public MultiStatus(@JsonProperty("multistatus") List statuses) { - this.statuses = checkNotNull(statuses); - } - - /** - * Returns list of Statuses. - * @return List of Statuses. - * @since 1.0.0 - */ - @JsonProperty("multistatus") - public List getStatuses() { return statuses; } - - /** - * Sets list of Statuses. - * @param statuses List of Statuses. - * @since 1.0.0 - */ - public void setStatuses(List statuses) { this.statuses = checkNotNull(statuses); } - - /** - * Returns iterator over the Statuses. - * @return Iterator over Statueses. - * @since 1.0.0 - */ - public Iterator iterator() { - return statuses.iterator(); - } - - @Override - public String toString() { - return String.format("MultiStatus(statuses=%s)", statuses); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(167, 173) - .append(statuses) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof MultiStatus)) return false; - - MultiStatus rhs = (MultiStatus)obj; - return new EqualsBuilder() - .append(statuses, rhs.statuses) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/Predicate.java b/src/main/java/com/tempodb/Predicate.java deleted file mode 100644 index efda175..0000000 --- a/src/main/java/com/tempodb/Predicate.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.tempodb; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.joda.time.Period; - -import static com.tempodb.util.Preconditions.*; - - -/** - * The representation of a predicate for a find datapoints call - * - * A Predicate allows you to specify a time period and function for a - * {@link DataPointFound} query. A Predicate allows you to find datapoints matching - * a specific condition. For instance, to find the hourly max (timestamp and value) - * the Predicate is specified as: - * - *

- *  import org.joda.time.Period;
- *
- *  Predicate predicate = new Predicate(Period.hours(1), "max");
- *  
- * @since 1.1.0 - */ -public class Predicate implements Serializable { - private Period period; - private String function; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - public Predicate() { - this(Period.minutes(1), "max"); - } - - /** - * Base constructor - * - * @param period The rollup period. - * @param function The function. - * @since 1.1.0 - */ - public Predicate(@JsonProperty("period") Period period, @JsonProperty("function") String function) { - this.period = checkNotNull(period); - this.function = checkNotNull(function); - } - - /** - * Returns the predicate period. - * @return The predicate period. - * @since 1.1.0 - */ - @JsonProperty("period") - public Period getPeriod() { return period; } - - /** - * Sets the predicate period. - * @param period The period. - * @since 1.1.0 - */ - public void setPeriod(Period period) { this.period = checkNotNull(period); } - - /** - * Returns the predicate function. - * @return The predicate folding function. - * @since 1.1.0 - */ - @JsonProperty("function") - public String getFunction() { return function; } - - /** Sets the predicate function. - * @param function The predicate function. - * @since 1.1.0 - */ - public void setFunction(String function) { this.function = checkNotNull(function); } - - @Override - public String toString() { - return String.format("Predicate(period=%s, function=\"%s\")", period.toString(), function.toLowerCase()); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(13, 41) - .append(period) - .append(function) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof Predicate)) return false; - - Predicate rhs = (Predicate)obj; - return new EqualsBuilder() - .append(period, rhs.period) - .append(function, rhs.function) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/Result.java b/src/main/java/com/tempodb/Result.java deleted file mode 100644 index f74e2c5..0000000 --- a/src/main/java/com/tempodb/Result.java +++ /dev/null @@ -1,200 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.nio.charset.Charset; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; - -import com.tempodb.MultiStatus; -import com.tempodb.json.Json; - - -/** - * Response from an API call. - * - *

The Result object returns the requested entity as well as provides - * information about the success state of the request. The Result state (getState()) should - * be inspected before trying to use the value. - * - *

In the event of a failure, the value is set to null. The code and message will provide more - * information about the failure. - * - *

In some cases, a request can partially succeed. This is indicated with state PARTIAL_SUCCESS. - * If a partial success occurs, the {@link MultiStatus} (member of Result) will be populated with - * more information about which request failed. - * - * @since 1.0.0 - */ -public class Result { - - private final T value; - private final int code; - private final String message; - private final MultiStatus multistatus; - - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - - public Result(T value, int code, String message) { - this(value, code, message, null); - } - - /** - * Used mainly for testing. - * @param value The returned value. - * @param code The status code of the entire result. - * @param message Message providing information about the state of the result. - * @param multistatus Provides information about partially successful result - * @since 1.0.0 - */ - public Result(T value, int code, String message, MultiStatus multistatus) { - this.value = value; - this.code = code; - this.message = message; - this.multistatus = multistatus; - } - - /** - * Base constructor. - * - * Uses the HttpResponse to generate the proper Result. - * @param response Http response - * @param klass Class of the value - * @since 1.0.0 - */ - public Result(HttpResponse response, Class klass) throws IOException { - T value = null; - int code = response.getStatusLine().getStatusCode(); - String message = response.getStatusLine().getReasonPhrase(); - MultiStatus multistatus = null; - - try { - switch(getState(code)) { - case SUCCESS: - value = newInstanceFromResponse(response, klass); - break; - case PARTIAL_SUCCESS: - multistatus = Json.loads(EntityUtils.toString(response.getEntity(), DEFAULT_CHARSET), MultiStatus.class); - break; - case FAILURE: - message = messageFromResponse(response); - break; - } - } finally { - // Consume and close the content stream - EntityUtils.consume(response.getEntity()); - } - - this.value = value; - this.code = code; - this.message = message; - this.multistatus = multistatus; - } - - /** - * Returns the value of the Result. - * @return Result value. Null if Result state is not SUCCESS. - * @since 1.0.0 - */ - public T getValue() { return value; } - - /** - * Returns the status code of the Result. - * @return Result status code. - * @since 1.0.0 - */ - public int getCode() { return code; } - - /** - * Returns the message of the Result. - * @return Result message. - * @since 1.0.0 - */ - public String getMessage() { return message; } - - /** - * Returns the MultiStatus of the Result. - * @return Result MultiStatus. Null if Result state is not PARTIAL_SUCCESS. - * @since 1.0.0 - */ - public MultiStatus getMultiStatus() { return multistatus; } - - /** - * Returns the State of the Result. - * The state should be used to determine the success state of the Result. - * @return Result state - * @since 1.0.0 - */ - public State getState() { return getState(code); } - - private static State getState(int code) { - State state = null; - if(((code / 100) == 2) && (code != 207)) { - state = State.SUCCESS; - } else if(code == 207) { - state = State.PARTIAL_SUCCESS; - } else { - state = State.FAILURE; - } - return state; - } - - private static T newInstanceFromResponse(HttpResponse response, Class klass) { - Throwable cause = null; - try { - if(klass == Void.class) { - return null; - } else { - Method method = klass.getDeclaredMethod("make", HttpResponse.class); - return klass.cast(method.invoke(null, response)); - } - } - catch (IllegalAccessException e) { cause = e; } - catch (InvocationTargetException e) { cause = e; } - catch (NoSuchMethodException e) { cause = e; } - - throw new IllegalArgumentException("Unknown class: " + klass, cause); - } - - private String messageFromResponse(HttpResponse response) throws IOException { - String message = EntityUtils.toString(response.getEntity(), DEFAULT_CHARSET); - if(message == null || message.equals("")) { - message = response.getStatusLine().getReasonPhrase(); - } - return message; - } - - @Override - public String toString() { - return String.format("Result(value=%s, code=%s, message=\"%s\", multistatus=%s)", value, code, message, multistatus); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(value) - .append(code) - .append(message) - .append(multistatus) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof Result)) return false; - - Result rhs = (Result)obj; - return new EqualsBuilder() - .append(value, rhs.value) - .append(code, rhs.code) - .append(message, rhs.message) - .append(multistatus, rhs.multistatus) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/Rollup.java b/src/main/java/com/tempodb/Rollup.java deleted file mode 100644 index 4eb097e..0000000 --- a/src/main/java/com/tempodb/Rollup.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.tempodb; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.joda.time.Period; - -import static com.tempodb.util.Preconditions.*; - - -/** - * The representation of a rollup of a single {@link Series}. - * - * A Rollup allows you to specify a time period and folding function for a - * {@link DataPoint} query. A Rollup represents a reduction in the amount of data - * returned to you. For instance, if you want to know the hourly average of a range - * of data, the Rollup is specified as: - * - *

- *  import org.joda.time.Period;
- *
- *  Rollup rollup = new Rollup(Period.hours(1), Fold.SUM);
- *  
- * @see Fold - * @since 1.0.0 - */ -public class Rollup implements Serializable { - private Period period; - private Fold fold; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - public Rollup() { - this(Period.minutes(1), Fold.SUM); - } - - /** - * Base constructor - * - * @param period The rollup period. - * @param fold The rollup folding function. - * @since 1.0.0 - */ - public Rollup(@JsonProperty("period") Period period, @JsonProperty("fold") Fold fold) { - this.period = checkNotNull(period); - this.fold = checkNotNull(fold); - } - - /** - * Returns the rollup period. - * @return The rollup period. - * @since 1.0.0 - */ - @JsonProperty("period") - public Period getPeriod() { return period; } - - /** - * Sets the rollup period. - * @param period The period. - * @since 1.0.0 - */ - public void setPeriod(Period period) { this.period = checkNotNull(period); } - - /** - * Returns the rollup folding function. - * @return The rollup folding function. - * @since 1.0.0 - */ - @JsonProperty("fold") - public Fold getFold() { return fold; } - - /** Sets the rollup folding function. - * @param fold The rollup folding function. - * @since 1.0.0 - */ - public void setFold(Fold fold) { this.fold = checkNotNull(fold); } - - @Override - public String toString() { - return String.format("Rollup(period=%s,fold=%s)", period.toString(), fold.toString().toLowerCase()); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(13, 41) - .append(period) - .append(fold) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof Rollup)) return false; - - Rollup rhs = (Rollup)obj; - return new EqualsBuilder() - .append(period, rhs.period) - .append(fold, rhs.fold) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/Segment.java b/src/main/java/com/tempodb/Segment.java deleted file mode 100644 index aac2052..0000000 --- a/src/main/java/com/tempodb/Segment.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.tempodb; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import static com.tempodb.util.Preconditions.*; - - -class Segment implements Iterable { - protected List data; - protected String next; - - public Segment(List data, String next) { - this.data = checkNotNull(data); - this.next = next; - } - - public List getData() { return this.data; } - public String getNext() { return this.next; } - - public Iterator iterator() { - return data.iterator(); - } -} diff --git a/src/main/java/com/tempodb/SegmentInnerIterator.java b/src/main/java/com/tempodb/SegmentInnerIterator.java deleted file mode 100644 index 334c9ed..0000000 --- a/src/main/java/com/tempodb/SegmentInnerIterator.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.tempodb; - -import java.util.Iterator; -import java.util.NoSuchElementException; - - -class SegmentInnerIterator implements Iterator { - private Iterator> segments; - private Iterator currentSegment; - - public SegmentInnerIterator(SegmentIterator> segments) { - this.segments = segments; - currentSegment = null; - } - - public boolean hasNext() { - boolean hasNext = true; - if(currentSegment == null) { - if(segments.hasNext()) { - currentSegment = segments.next().iterator(); - } else { - return false; - } - } - - while(!currentSegment.hasNext() && segments.hasNext()) { - currentSegment = segments.next().iterator(); - } - return currentSegment.hasNext(); - } - - public T next() { - if(!hasNext()) { - throw new NoSuchElementException(); - } - return currentSegment.next(); - } - - public final void remove() { - throw new UnsupportedOperationException(); - } -} diff --git a/src/main/java/com/tempodb/SegmentIterator.java b/src/main/java/com/tempodb/SegmentIterator.java deleted file mode 100644 index 3d5055d..0000000 --- a/src/main/java/com/tempodb/SegmentIterator.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.tempodb; - -import java.util.Iterator; -import java.util.NoSuchElementException; - -import static com.tempodb.util.Preconditions.*; -import org.apache.http.HttpRequest; - - -class SegmentIterator> implements Iterator { - - private final Client client; - private T segment; - private Class klass; - - public SegmentIterator(Client client, T initial, Class klass) { - this.client = checkNotNull(client); - this.segment = checkNotNull(initial); - this.klass = klass; - } - - @Override - public final T next() { - if(!hasNext()) { - throw new NoSuchElementException(); - } - T rv = this.segment; - - if(this.segment.getNext() != null && !this.segment.getNext().equals("")) { - HttpRequest request = client.buildRequest(this.segment.getNext()); - Result result = client.execute(request, klass); - if(result.getState() == State.SUCCESS) { - this.segment = result.getValue(); - } else { - throw new TempoDBException(result.getMessage(), result.getCode()); - } - } else { - this.segment = null; - } - return rv; - } - - @Override - public final boolean hasNext() { - return segment != null; - } - - @Override public final void remove() { - throw new UnsupportedOperationException(); - } -} diff --git a/src/main/java/com/tempodb/Series.java b/src/main/java/com/tempodb/Series.java deleted file mode 100644 index 0b1167e..0000000 --- a/src/main/java/com/tempodb/Series.java +++ /dev/null @@ -1,164 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.io.Serializable; -import java.nio.charset.Charset; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; - -import com.tempodb.json.Json; -import static com.tempodb.util.Preconditions.*; - - -/** - * A data series and it's metadata. - * - * @since 1.0.0 - */ -public class Series implements Serializable { - - private String key; - private String name; - private Set tags; - private Map attributes; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - - public Series() { - this("", "", new LinkedHashSet(), new HashMap()); - } - - /** - * Key-only constructor. - *
    - *
  • name default to ""
  • - *
  • tags default to empty set
  • - *
  • attributes default to empty map
  • - *
- * @param key Series key - * @since 1.0.0 - */ - public Series(String key) { - this(key, "", new LinkedHashSet(), new HashMap()); - } - - /** - * Base constructor - * - * @param key Series key - * @param name Human readable name for the Series - * @param tags Set of tags - * @param attributes Map of key/value pair metadata - * @since 1.0.0 - */ - public Series(String key, String name, Set tags, Map attributes) { - this.key = checkNotNull(key); - this.name = checkNotNull(name); - this.tags = checkNotNull(tags); - this.attributes = checkNotNull(attributes); - } - - /** - * Returns the key of this Series. - * @return Series key. - * @since 1.0.0 - */ - public String getKey() { return key; } - - /** - * Sets the key of this Series. - * @param key Series key. - * @since 1.0.0 - */ - public void setKey(String key) { this.key = checkNotNull(key); } - - /** - * Returns the name of this Series. - * @return Series name. - * @since 1.0.0 - */ - public String getName() { return name; } - - /** - * Sets the name of this Series. - * @param name Series name. - * @since 1.0.0 - */ - public void setName(String name) { this.name = checkNotNull(name); } - - - /** - * Returns the tags of this Series. - * @return Series tags. - * @since 1.0.0 - */ - public Set getTags() { return tags; } - - /** - * Sets the tags of this Series. - * @param tags Series tags. - * @since 1.0.0 - */ - public void setTags(Set tags) { this.tags = checkNotNull(tags); } - - /** - * Returns the attributes of this Series. - * @return Series attributes. - * @since 1.0.0 - */ - public Map getAttributes() { return attributes; } - - /** - * Sets the attributes of this Series. - * @param attributes Series attributes. - * @since 1.0.0 - */ - public void setAttributes(Map attributes) { this.attributes = checkNotNull(attributes); } - - static Series make(HttpResponse response) throws IOException { - String body = EntityUtils.toString(response.getEntity(), DEFAULT_CHARSET); - Series series = Json.loads(body, Series.class); - return series; - } - - @Override - public String toString() { - return String.format("Series(key=%s, name=%s, tags=%s, attributes=%s)", key, name, tags, attributes); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(119, 123) - .append(key) - .append(name) - .append(tags) - .append(attributes) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof Series)) return false; - - Series rhs = (Series)obj; - return new EqualsBuilder() - .append(key, rhs.key) - .append(name, rhs.name) - .append(tags, rhs.tags) - .append(attributes, rhs.attributes) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/SeriesCursor.java b/src/main/java/com/tempodb/SeriesCursor.java deleted file mode 100644 index 50e702f..0000000 --- a/src/main/java/com/tempodb/SeriesCursor.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.tempodb; - -import java.net.URI; -import java.util.Iterator; - -import org.apache.http.HttpRequest; - -import static com.tempodb.util.Preconditions.*; - - -class SeriesCursor implements Cursor { - private final URI uri; - private final Client client; - - public SeriesCursor(URI uri, Client client) { - this.uri = checkNotNull(uri); - this.client = checkNotNull(client); - } - - public Iterator iterator() { - HttpRequest request = client.buildRequest(uri.toString()); - Result result = client.execute(request, SeriesSegment.class); - - Iterator iterator = null; - if(result.getState() == State.SUCCESS) { - @SuppressWarnings("unchecked") // This cast is always ok - SegmentIterator> segments = new SegmentIterator(client, result.getValue(), SeriesSegment.class); - iterator = new SegmentInnerIterator(segments); - } else { - throw new TempoDBException(result.getMessage(), result.getCode()); - } - return iterator; - } -} diff --git a/src/main/java/com/tempodb/SeriesSegment.java b/src/main/java/com/tempodb/SeriesSegment.java deleted file mode 100644 index 78bdc7c..0000000 --- a/src/main/java/com/tempodb/SeriesSegment.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; - -import com.tempodb.http.PageLinks; -import com.tempodb.json.Json; -import static com.tempodb.util.Preconditions.*; - - -public class SeriesSegment extends Segment { - - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - - public SeriesSegment() { - this(new ArrayList(), ""); - } - - @JsonCreator - public SeriesSegment(@JsonProperty("data") List data) { - super(data, null); - } - - public SeriesSegment(List data, String next) { - super(data, next); - } - - static SeriesSegment make(HttpResponse response) throws IOException { - String body = EntityUtils.toString(response.getEntity(), DEFAULT_CHARSET); - SeriesSegment segment = Json.loads(body, SeriesSegment.class); - PageLinks links = new PageLinks(response); - segment.next = links.getNext(); - return segment; - } - - @Override - public String toString() { - return String.format("SeriesSegment(data=%s, next=%s)", data, next); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(127, 129) - .append(data) - .append(next) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof SeriesSegment)) return false; - - SeriesSegment rhs = (SeriesSegment)obj; - return new EqualsBuilder() - .append(data, rhs.data) - .append(next, rhs.next) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/SingleValue.java b/src/main/java/com/tempodb/SingleValue.java deleted file mode 100644 index 41e88c3..0000000 --- a/src/main/java/com/tempodb/SingleValue.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.io.Serializable; -import java.nio.charset.Charset; - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; -import org.joda.time.DateTime; - -import com.tempodb.json.Json; -import static com.tempodb.util.Preconditions.*; - -/** - * A Series/DataPoint pair for use with the getSingleValue calls - * @since 1.1.0 - */ -public class SingleValue implements Serializable { - - private Series series; - private DataPoint datapoint; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - - public SingleValue() { - this(new Series(), new DataPoint()); - } - - /** - * Base constructor - * @param series The Series associated with the datapoint - * @param datapoint The datapoint - * @since 1.1.0 - */ - public SingleValue(@JsonProperty("series") Series series, @JsonProperty("data") DataPoint datapoint) { - this.series = checkNotNull(series); - this.datapoint = checkNotNull(datapoint); - } - - /** - * Returns the series of this SingleValue. - * @return the series - * @since 1.1.0 - */ - @JsonProperty("series") - public Series getSeries() { return series; } - - /** - * Sets the series of this SingleValue. - * @param series The series of this SingleValue - * @since 1.1.0 - */ - public void setSeries(Series series) { this.series = checkNotNull(series); } - - /** - * Returns the datapoint of this SingleValue. - * @return the datapoint - * @since 1.1.0 - */ - @JsonProperty("data") - public DataPoint getDataPoint() { return datapoint; } - - /** - * Sets the datapoint of this SingleValue. - * @param datapoint The DataPoint of this SingleValue - * @since 1.1.0 - */ - public void setDataPoint(DataPoint datapoint) { this.datapoint = checkNotNull(datapoint); } - - static SingleValue make(HttpResponse response) throws IOException { - String body = EntityUtils.toString(response.getEntity(), DEFAULT_CHARSET); - SingleValue value = Json.loads(body, SingleValue.class); - return value; - } - - @Override - public String toString() { - return String.format("SingleValue(series=%s, datapoint=%s)", series.toString(), datapoint.toString()); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(19, 31) - .append(series) - .append(datapoint) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof SingleValue)) return false; - - SingleValue rhs = (SingleValue)obj; - return new EqualsBuilder() - .append(series, rhs.series) - .append(datapoint, rhs.datapoint) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/SingleValueCursor.java b/src/main/java/com/tempodb/SingleValueCursor.java deleted file mode 100644 index 6791195..0000000 --- a/src/main/java/com/tempodb/SingleValueCursor.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.tempodb; - -import java.net.URI; -import java.util.Iterator; - -import org.apache.http.HttpRequest; - -import static com.tempodb.util.Preconditions.*; - - -class SingleValueCursor implements Cursor { - private final URI uri; - private final Client client; - - public SingleValueCursor(URI uri, Client client) { - this.uri = checkNotNull(uri); - this.client = checkNotNull(client); - } - - public Iterator iterator() { - HttpRequest request = client.buildRequest(uri.toString()); - Result result = client.execute(request, SingleValueSegment.class); - - Iterator iterator = null; - if(result.getState() == State.SUCCESS) { - @SuppressWarnings("unchecked") // This cast is always ok - SegmentIterator> segments = new SegmentIterator(client, result.getValue(), SingleValueSegment.class); - iterator = new SegmentInnerIterator(segments); - } else { - throw new TempoDBException(result.getMessage(), result.getCode()); - } - return iterator; - } -} diff --git a/src/main/java/com/tempodb/SingleValueSegment.java b/src/main/java/com/tempodb/SingleValueSegment.java deleted file mode 100644 index 434e8a5..0000000 --- a/src/main/java/com/tempodb/SingleValueSegment.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; - -import com.tempodb.http.PageLinks; -import com.tempodb.json.Json; -import static com.tempodb.util.Preconditions.*; - - -public class SingleValueSegment extends Segment { - - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - - public SingleValueSegment() { - this(new ArrayList(), ""); - } - - @JsonCreator - public SingleValueSegment(@JsonProperty("data") List data) { - super(data, null); - } - - public SingleValueSegment(List data, String next) { - super(data, next); - } - - static SingleValueSegment make(HttpResponse response) throws IOException { - String body = EntityUtils.toString(response.getEntity(), DEFAULT_CHARSET); - SingleValueSegment segment = Json.loads(body, SingleValueSegment.class); - PageLinks links = new PageLinks(response); - segment.next = links.getNext(); - return segment; - } - - @Override - public String toString() { - return String.format("SingleValueSegment(data=%s, next=%s)", data, next); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(127, 129) - .append(data) - .append(next) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof SingleValueSegment)) return false; - - SingleValueSegment rhs = (SingleValueSegment)obj; - return new EqualsBuilder() - .append(data, rhs.data) - .append(next, rhs.next) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/State.java b/src/main/java/com/tempodb/State.java deleted file mode 100644 index 40aae50..0000000 --- a/src/main/java/com/tempodb/State.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.tempodb; - - -/** - * The success state of a {@link Result}. - * - * {@link Result}'s can complete successfully, completely fail, or partially succeed. - * @since 1.0.0 - */ -public enum State { - /** - * Request failed completely. - * @since 1.0.0 - */ - FAILURE, - - /** - * Request completed successfully. - * @since 1.0.0 - */ - SUCCESS, - - /** Request partially succeeded. - * Check the MultiStatus for more information. - * @see MultiStatus - * @since 1.0.0 - */ - PARTIAL_SUCCESS -} diff --git a/src/main/java/com/tempodb/Status.java b/src/main/java/com/tempodb/Status.java deleted file mode 100644 index 76a2346..0000000 --- a/src/main/java/com/tempodb/Status.java +++ /dev/null @@ -1,100 +0,0 @@ -package com.tempodb; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; - -import static com.tempodb.util.Preconditions.*; - - -/** - * Information about the success of a single request in an API call that can partially succeed. - * A bulk write of {@link DataPoint}s can partially succeed. This object provides information about - * the cause of the failure for a single request. - * - * @since 1.0.0 - */ -public class Status implements Serializable { - - private int code; - private List messages; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - public Status() { - this(0, new ArrayList()); - } - - /** - * Base constructor - * - * @param code The status code of the request. - * @param messages A list of validation error messages. - * @since 1.0.0 - */ - public Status(@JsonProperty("status") int code, @JsonProperty("messages") List messages) { - this.code = checkNotNull(code); - this.messages = checkNotNull(messages); - } - - /** - * Returns the status code. - * @return The status code. - * @since 1.0.0 - */ - @JsonProperty("status") - public int getCode() { return code; } - - /** - * Sets the status code. - * @param code The status code. - * @since 1.0.0 - */ - public void setCode(int code) { this.code = checkNotNull(code); } - - /** - * Returns the validation error messages. - * @return A list of validation error messages. - * @since 1.0.0 - */ - @JsonProperty("messages") - public List getMessages() { return messages; } - - /** - * Sets the validation error messages. - * @param messages A list of validation error messages. - * @since 1.0.0 - */ - public void setMessages(List messages) { this.messages = checkNotNull(messages); } - - @Override - public String toString() { - return String.format("Status(code=%d,messages=%s)", code, messages); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(157, 163) - .append(code) - .append(messages) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof Status)) return false; - - Status rhs = (Status)obj; - return new EqualsBuilder() - .append(code, rhs.code) - .append(messages, rhs.messages) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/Summary.java b/src/main/java/com/tempodb/Summary.java deleted file mode 100644 index cbcd264..0000000 --- a/src/main/java/com/tempodb/Summary.java +++ /dev/null @@ -1,142 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.io.Serializable; -import java.nio.charset.Charset; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; - -import com.tempodb.json.Json; -import static com.tempodb.util.Preconditions.*; - - -/** - * A set of summary statistics for a series. - * - * @since 1.1.0 - */ -public class Summary implements Map, Serializable { - - private Series series; - private Interval interval; - private Map summary; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - - public Summary() { - this(new Series(""), new Interval(new DateTime(), new DateTime()), new HashMap()); - } - - /** - * Base constructor - * - * @param series Series - * @param interval Interval of data to calculate the statistics - * @param summary Map of statistic string to value - * @since 1.1.0 - */ - public Summary(Series series, Interval interval, Map summary) { - this.series = checkNotNull(series); - this.interval = checkNotNull(interval); - this.summary = checkNotNull(summary); - } - - /** - * Returns the series of this Summary - * @return Summary series. - * @since 1.1.0 - */ - public Series getSeries() { return series; } - - /** - * Sets the series of this Summary. - * @param series Summary series. - * @since 1.1.0 - */ - public void setSeries(Series series) { this.series = checkNotNull(series); } - - /** - * Returns the interval of this Summary. - * @return Summary interval. - * @since 1.1.0 - */ - public Interval getInterval() { return interval; } - - /** - * Sets the interval of this Summary. - * @param interval Summary interval. - * @since 1.1.0 - */ - public void setInterval(Interval interval) { this.interval = checkNotNull(interval); } - - public void clear() { summary.clear(); } - - public boolean containsKey(Object key) { return summary.containsKey(key); } - - public boolean containsValue(Object value) { return summary.containsValue(value); } - - public Set> entrySet() { return summary.entrySet(); } - - public Number get(Object key) { return summary.get(key); } - - public boolean isEmpty() { return summary.isEmpty(); } - - public Set keySet() { return summary.keySet(); } - - public Number put(String key, Number value) { return summary.put(key, value); } - - public void putAll(Map m) { summary.putAll(m); } - - public Number remove(Object key) { return summary.remove(key); } - - public int size() { return summary.size(); } - - public Collection values() { return summary.values(); } - - static Summary make(HttpResponse response) throws IOException { - String body = EntityUtils.toString(response.getEntity(), DEFAULT_CHARSET); - Summary summary = Json.loads(body, Summary.class); - return summary; - } - - @Override - public String toString() { - return String.format("Summary(series=%s, interval=%s, summary=%s)", series, interval, summary); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(119, 123) - .append(series) - .append(interval) - .append(summary) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof Summary)) return false; - - Summary rhs = (Summary)obj; - return new EqualsBuilder() - .append(series, rhs.series) - .append(interval, rhs.interval) - .append(summary, rhs.summary) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/TempoDBException.java b/src/main/java/com/tempodb/TempoDBException.java deleted file mode 100644 index 0fbc0b2..0000000 --- a/src/main/java/com/tempodb/TempoDBException.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.tempodb; - -public class TempoDBException extends RuntimeException { - private int code = 0; - - public TempoDBException() { super(); } - - public TempoDBException(String message, int code) { - super(message); - this.code = code; - } - - public TempoDBException(String message, Throwable cause, int code) { - super(message, cause); - this.code = code; - } -} diff --git a/src/main/java/com/tempodb/WritableDataPoint.java b/src/main/java/com/tempodb/WritableDataPoint.java deleted file mode 100644 index 84b49f0..0000000 --- a/src/main/java/com/tempodb/WritableDataPoint.java +++ /dev/null @@ -1,113 +0,0 @@ -package com.tempodb; - -import java.io.Serializable; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.joda.time.DateTime; - -import static com.tempodb.util.Preconditions.*; - - -/** - * DataPoint for a Series, used for bulk writing of DataPoints. - *

Allows you to specify a timestamp/value pair, as well as the {@link Series} - * that it is associated with. - * @since 1.0.0 - */ -public class WritableDataPoint implements Serializable { - - private Series series; - private DateTime timestamp; - private Number value; - - /** Serialization lock */ - private static final long serialVersionUID = 1L; - - public WritableDataPoint() { - this(new Series(""), new DateTime(), 0.0); - } - - /** - * Base constructor - * @param series {@link Series} for the DataPoint - * @param timestamp Timestamp for the DataPoint - * @param value Value for the DataPoint - * @since 1.0.0 - */ - public WritableDataPoint(Series series, DateTime timestamp, Number value) { - this.series = checkNotNull(series); - this.timestamp = checkNotNull(timestamp); - this.value = checkNotNull(value); - } - - /** - * Returns the {@link Series} of this WritableDataPoint. - * @return the {@link Series} - * @since 1.0.0 - */ - public Series getSeries() { return series; } - - /** - * Sets the {@link Series} of this WritableDataPoint. - * @param series The {@link Series} - * @since 1.0.0 - */ - public void setSeries(Series series) { this.series = checkNotNull(series); } - - /** - * Returns the timestamp of this WritableDataPoint. - * @return the timestamp - * @since 1.0.0 - */ - public DateTime getTimestamp() { return timestamp; } - - /** - * Sets the timestamp of this WritableDataPoint. - * @param timestamp The timestamp of this WritableDataPoint - * @since 1.0.0 - */ - public void setTimestamp(DateTime timestamp) { this.timestamp = checkNotNull(timestamp); } - - /** - * Returns the value of this WritableDataPoint. - * @return the value - * @since 1.0.0 - */ - public Number getValue() { return value; } - - /** - * Sets the value of this WritableDataPoint. - * @param value The value of this WritableDataPoint - * @since 1.0.0 - */ - public void setValue(Number value) { this.value = checkNotNull(value); } - - @Override - public String toString() { - return String.format("WritableDataPoint(series=%s, timestamp=%s, value=%s", series, timestamp, value); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(137, 139) - .append(series) - .append(timestamp) - .append(value) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof WritableDataPoint)) return false; - - WritableDataPoint rhs = (WritableDataPoint)obj; - return new EqualsBuilder() - .append(series, rhs.series) - .append(timestamp, rhs.timestamp) - .append(value, rhs.value) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/WriteRequest.java b/src/main/java/com/tempodb/WriteRequest.java deleted file mode 100644 index 7dae16a..0000000 --- a/src/main/java/com/tempodb/WriteRequest.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.tempodb; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.apache.commons.lang3.builder.EqualsBuilder; -import org.apache.commons.lang3.builder.HashCodeBuilder; - -import static com.tempodb.util.Preconditions.*; - - -/** - * A request for writing multiple DataPoints to multiple Series. - *

The request is created and datapoints are added for a Series. - * @since 1.0.0 - */ -public class WriteRequest implements Iterable { - - private final List data; - - /** - * Base constructor - * @since 1.0.0 - */ - public WriteRequest() { - this.data = new ArrayList(); - } - - /** - * Adds a DataPoint to the request for a Series. - * @param series The Series to write to. - * @param datapoint The DataPoint to write. - * @return The updated request. - * @since 1.0.0 - */ - public WriteRequest add(Series series, DataPoint datapoint) { - WritableDataPoint mdp = new WritableDataPoint(series, datapoint.getTimestamp(), datapoint.getValue()); - data.add(mdp); - return this; - } - - /** - * Adds a list of DataPoints to the request for a Series. - * @param series The Series to write to. - * @param datapoints The list of DataPoints to write. - * @return The updated request. - * @since 1.0.0 - */ - public WriteRequest add(Series series, List datapoints) { - for(DataPoint datapoint : datapoints) { - WritableDataPoint mdp = new WritableDataPoint(series, datapoint.getTimestamp(), datapoint.getValue()); - data.add(mdp); - } - return this; - } - - @Override - public Iterator iterator() { - return data.iterator(); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(257, 263) - .append(data) - .toHashCode(); - } - - @Override - public boolean equals(Object obj) { - if(obj == null) return false; - if(obj == this) return true; - if(!(obj instanceof WriteRequest)) return false; - - WriteRequest rhs = (WriteRequest)obj; - return new EqualsBuilder() - .append(data, rhs.data) - .isEquals(); - } -} diff --git a/src/main/java/com/tempodb/client/Client.java b/src/main/java/com/tempodb/client/Client.java new file mode 100644 index 0000000..8f5538b --- /dev/null +++ b/src/main/java/com/tempodb/client/Client.java @@ -0,0 +1,518 @@ +package com.tempodb.client; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.apache.http.HttpHost; +import org.apache.http.NameValuePair; +import org.apache.http.auth.AuthScope; +import org.apache.http.auth.UsernamePasswordCredentials; +import org.apache.http.client.AuthCache; +import org.apache.http.client.HttpClient; +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.client.protocol.ClientContext; +import org.apache.http.client.utils.URLEncodedUtils; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.auth.BasicScheme; +import org.apache.http.impl.client.BasicAuthCache; +import org.apache.http.impl.client.BasicResponseHandler; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager; +import org.apache.http.message.BasicNameValuePair; +import org.apache.http.params.BasicHttpParams; +import org.apache.http.params.HttpConnectionParams; +import org.apache.http.params.HttpParams; +import org.apache.http.params.HttpProtocolParams; +import org.apache.http.protocol.BasicHttpContext; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.joda.JodaModule; + +import org.joda.time.DateTime; +import org.joda.time.format.DateTimeFormat; +import org.joda.time.format.DateTimeFormatter; + +import com.tempodb.models.BulkDataSet; +import com.tempodb.models.DataPoint; +import com.tempodb.models.DataSet; +import com.tempodb.models.Filter; +import com.tempodb.models.Series; + + +/** + * Stores the session information for authenticating and accessing TempoDB. + * Your api key and secret is required. The Client also allows you to specify + * the hostname, port, and protocol (http or https). This is used if you are on + * a private cluster. The default hostname and port should work for the standard cluster. + *

+ * All access to data is made through a client instance. + */ +public class Client { + + private String key; + private String secret; + private String host; + private int port; + private boolean secure; + + private DefaultHttpClient _client = null; + private HttpHost _targetHost = null; + private BasicHttpContext _context = null; + private ObjectMapper _mapper = null; + private String _version = null; + private final DateTimeFormatter iso8601 = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); + + /** How often the monitoring thread checks for connections to close. */ + private static final int DEFAULT_TIMEOUT_MILLIS = 30000; // 30 seconds + + private static final String API_VERSION = "v1"; + + private enum HttpMethod { GET, POST, PUT, DELETE } + + /** + * @param key Api key + * @param secret Api secret + * @param host Hostname of the api server + * @param port Port that the api server is listening on + * @param secure Uses http if false, https if true + */ + public Client(String key, String secret, String host, int port, boolean secure) { + this.key = key; + this.secret = secret; + this.host = host; + this.port = port; + this.secure = secure; + } + + /** + * Creates a new series in the database. + * + * @return A Series + */ + public Series createSeries() throws Exception { + return createSeries(""); + } + + /** + * Creates a new series in the database with a key. + * + * @param key A user-defined key for the series + * @return A Series + */ + public Series createSeries(String key) throws Exception { + String url = "/series/"; + String json = String.format("{\"key\":\"%s\"}", key); + + ObjectMapper mapper = getMapper(); + String response = request(url, HttpMethod.POST, json); + return mapper.readValue(response, Series.class); + } + + /** + * Gets a list of all series in the database. + * + * @return A list of Series + */ + public List getSeries() throws Exception { + return getSeries(new Filter()); + } + + /** + * Gets a list of series filtered by the provided Filter. + * + * @param filter A Filter instance to filter the list + * @return A list of Series + */ + public List getSeries(Filter filter) throws Exception { + String filterString = URLEncodedUtils.format(filter.getParams(), "UTF-8"); + String json = request(String.format("/series/?%s", filterString)); + ObjectMapper mapper = getMapper(); + + ArrayList result = mapper.readValue(json, new TypeReference>() {}); + return result; + } + + /** + * Updates a Series's metadata + * + * @param series The series to update. + * @return The updated Series + */ + public Series updateSeries(Series series) throws Exception { + String url = String.format("/series/id/%s/", series.getId()); + + ObjectMapper mapper = getMapper(); + String json = mapper.writeValueAsString(series); + + String response = request(url, HttpMethod.PUT, json); + return mapper.readValue(response, Series.class); + } + + /** + * Reads a list of DataSet by the provided filter. + * + * @param start The start time of the range + * @param end The end time of the range + * @param filter A Filter instance to filter the series + * @return A list of DataSets + */ + public List read(DateTime start, DateTime end, Filter filter) throws Exception { + return read(start, end, filter, null, null); + } + + /** + * Reads a list of DataSet by the provided filter and rolluped by the interval + * + * @param start The start time of the range + * @param end The end time of the range + * @param filter A Filter instance to filter the series + * @param interval An interval for the rollup. (e.g. 1min, 15min, 1hour, 1day, 1month) + * @return A list of DataSets + */ + public List read(DateTime start, DateTime end, Filter filter, String interval) throws Exception { + return read(start, end, filter, interval, null); + } + + /** + * Reads a list of DataSet by the provided filter and rolluped by the interval + * + * @param start The start time of the range + * @param end The end time of the range + * @param filter A Filter instance to filter the series + * @param interval An interval for the rollup. (e.g. 1min, 15min, 1hour, 1day, 1month) + * @param function A function for the rollup. (e.g. min, max, sum, avg, stddev, count) + * @return A list of DataSets + */ + public List read(DateTime start, DateTime end, Filter filter, String interval, String function) throws Exception { + List params = new ArrayList(); + params.add(new BasicNameValuePair("start", start.toString(iso8601))); + params.add(new BasicNameValuePair("end", end.toString(iso8601))); + + if (filter != null) + params.addAll(filter.getParams()); + + if (interval != null) + params.add(new BasicNameValuePair("interval", interval)); + + if (function != null) + params.add(new BasicNameValuePair("function", function)); + + String qsParams = URLEncodedUtils.format(params, "UTF-8"); + String url = String.format("/data/?%s", qsParams); + String json = request(url); + + ObjectMapper mapper = getMapper(); + List datasets = mapper.readValue(json, new TypeReference>() {}); + return datasets; + } + + /** + * Reads a DataSet by id + * + * @param seriesId The id of the series + * @param start The start time of the range + * @param end The end time of the range + * @return A DataSet + */ + public DataSet readId(String seriesId, DateTime start, DateTime end) throws Exception { + return readId(seriesId, start, end, null, null); + } + + /** + * Reads a DataSet by id + * + * @param seriesId The id of the series + * @param start The start time of the range + * @param end The end time of the range + * @param interval An interval for the rollup. (e.g. 1min, 15min, 1hour, 1day, 1month) + * @return A DataSet + */ + public DataSet readId(String seriesId, DateTime start, DateTime end, String interval) throws Exception { + return readId(seriesId, start, end, interval, null); + } + + /** + * Reads a DataSet by id + * + * @param seriesId The id of the series + * @param start The start time of the range + * @param end The end time of the range + * @param interval An interval for the rollup. (e.g. 1min, 15min, 1hour, 1day, 1month) + * @param function A function for the rollup. (e.g. min, max, sum, avg, stddev, count) + * @return A DataSet + */ + public DataSet readId(String seriesId, DateTime start, DateTime end, String interval, String function) throws Exception { + return readOne("id", seriesId, start, end, interval, function); + } + + /** + * Reads a DataSet by key + * + * @param seriesKey The key of the series + * @param start The start time of the range + * @param end The end time of the range + * @return A DataSet + */ + public DataSet readKey(String seriesKey, DateTime start, DateTime end) throws Exception { + return readKey(seriesKey, start, end, null, null); + } + + /** + * Reads a DataSet by key + * + * @param seriesKey The key of the series + * @param start The start time of the range + * @param end The end time of the range + * @param interval An interval for the rollup. (e.g. 1min, 15min, 1hour, 1day, 1month) + * @return A DataSet + */ + public DataSet readKey(String seriesKey, DateTime start, DateTime end, String interval) throws Exception { + return readKey(seriesKey, start, end, interval, null); + } + + /** + * Reads a DataSet by key + * + * @param seriesKey The key of the series + * @param start The start time of the range + * @param end The end time of the range + * @param interval An interval for the rollup. (e.g. 1min, 15min, 1hour, 1day, 1month) + * @param function A function for the rollup. (e.g. min, max, sum, avg, stddev, count) + * @return A DataSet + */ + public DataSet readKey(String seriesKey, DateTime start, DateTime end, String interval, String function) throws Exception { + return readOne("key", seriesKey, start, end, interval, function); + } + + /** + * Writes a DataSet by id + * + * @param seriesId The id of the series + * @param data A list of DataPoints to write + * @return The list of DataPoints written + */ + public List writeId(String seriesId, List data) throws Exception { + return write("id", seriesId, data); + } + + /** + * Writes a DataSet by key + * + * @param seriesKey The key of the series + * @param data A list of DataPoints to write + * @return The list of DataPoints written + */ + public List writeKey(String seriesKey, List data) throws Exception { + return write("key", seriesKey, data); + } + + /** + * Writes a set of datapoints for different series for the same timestamp + * + * @param dataset A BulkDataSet to write + */ + public void bulkWrite(BulkDataSet dataset) throws Exception { + String url = "/data/"; + + ObjectMapper mapper = getMapper(); + String json = mapper.writeValueAsString(dataset); + + request(url, HttpMethod.POST, json); + } + + /** + * Increments a DataSet by id + * + * @param seriesId The id of the series + * @param data A list of DataPoints to increment. The value of each DataPoint specifies the amount to increment. + * @return The list of DataPoints written + */ + public List incrementId(String seriesId, List data) throws Exception { + return increment("id", seriesId, data); + } + + /** + * Increments a DataSet by key + * + * @param seriesKey The key of the series + * @param data A list of DataPoints to increment. The value of each DataPoint specifies the amount to increment. + * @return The list of DataPoints written + */ + public List incrementKey(String seriesKey, List data) throws Exception { + return increment("key", seriesKey, data); + } + + /** + * Increments a set of datapoints for different series for the same timestamp. Similar to a write, but it increments the values instead + * of overwriting. + * + * @param dataset A BulkDataSet to write + */ + public void bulkIncrement(BulkDataSet dataset) throws Exception { + String url = "/increment/"; + + ObjectMapper mapper = getMapper(); + String json = mapper.writeValueAsString(dataset); + + request(url, HttpMethod.POST, json); + } + + private DataSet readOne(String seriesType, String seriesValue, DateTime start, DateTime end, String interval, String function) throws Exception { + List params = new ArrayList(); + params.add(new BasicNameValuePair("start", start.toString(iso8601))); + params.add(new BasicNameValuePair("end", end.toString(iso8601))); + + if (interval != null) + params.add(new BasicNameValuePair("interval", interval)); + + if (function != null) + params.add(new BasicNameValuePair("function", function)); + + String qsParams = URLEncodedUtils.format(params, "UTF-8"); + + String url = String.format("/series/%s/%s/data/?%s", seriesType, seriesValue, qsParams); + String json = request(url); + + ObjectMapper mapper = getMapper(); + DataSet dataset = mapper.readValue(json, DataSet.class); + return dataset; + } + + private List write(String seriesType, String seriesValue, List data) throws Exception { + String url = String.format("/series/%s/%s/data/", seriesType, seriesValue); + + ObjectMapper mapper = getMapper(); + String json = mapper.writeValueAsString(data); + + request(url, HttpMethod.POST, json); + return data; + } + + private List increment(String seriesType, String seriesValue, List data) throws Exception { + String url = String.format("/series/%s/%s/increment/", seriesType, seriesValue); + + ObjectMapper mapper = getMapper(); + String json = mapper.writeValueAsString(data); + + request(url, HttpMethod.POST, json); + return data; + } + + private String request(String url) throws Exception { + return request(url, HttpMethod.GET, ""); + } + + private String request(String url, HttpMethod method) throws Exception { + return request(url, method, ""); + } + + private String request(String url, HttpMethod method, String body) throws Exception { + String protocol = secure ? "https://" : "http://"; + String portString = (port == 80) ? "" : ":" + port; + String uri = protocol + host + portString + "/" + API_VERSION + url; + + String rv = ""; + switch (method) { + case POST: + HttpPost post = new HttpPost(uri); + post.setEntity(new StringEntity(body)); + rv = execute(post); + break; + + case PUT: + HttpPut put = new HttpPut(uri); + put.setEntity(new StringEntity(body)); + rv = execute(put); + break; + + case GET: + default: // Drop down by design + HttpGet get = new HttpGet(uri); + rv = execute(get); + break; + } + + return rv; + } + + private String execute(HttpUriRequest uri) throws Exception { + HttpClient client = getHttpClient(); + + HttpHost targetHost = getTargetHost(); + BasicHttpContext context = getContext(); + + ResponseHandler responseHandler = new BasicResponseHandler(); + String responseBody = client.execute(targetHost, uri, responseHandler, context); + return responseBody; + } + + private synchronized HttpClient getHttpClient() { + if (_client == null) { + HttpParams httpParams = new BasicHttpParams(); + HttpConnectionParams.setConnectionTimeout(httpParams, DEFAULT_TIMEOUT_MILLIS); + HttpConnectionParams.setSoTimeout(httpParams, DEFAULT_TIMEOUT_MILLIS); + HttpConnectionParams.setSocketBufferSize(httpParams, 8192); + HttpProtocolParams.setUserAgent(httpParams, String.format("tempodb-java/%s", getVersion())); + + _client = new DefaultHttpClient(new ThreadSafeClientConnManager(), httpParams); + + _client.getCredentialsProvider().setCredentials( + new AuthScope(host, port), + new UsernamePasswordCredentials(key, secret)); + } + return _client; + } + + private synchronized HttpHost getTargetHost() { + if (_targetHost == null) { + _targetHost = new HttpHost(host, port, secure ? "https" : "http"); + } + return _targetHost; + } + + private synchronized BasicHttpContext getContext() { + if (_context == null) { + HttpHost targetHost = getTargetHost(); + + AuthCache authCache = new BasicAuthCache(); + BasicScheme basicAuth = new BasicScheme(); + authCache.put(targetHost, basicAuth); + + _context = new BasicHttpContext(); + _context.setAttribute(ClientContext.AUTH_CACHE, authCache); + } + return _context; + } + + private synchronized ObjectMapper getMapper() { + if (_mapper == null) { + _mapper = new ObjectMapper(); + _mapper.registerModule(new JodaModule()); + _mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + } + return _mapper; + } + + private String getVersion() { + if(_version == null) { + try { + InputStream is = getClass().getResourceAsStream( "/build.properties" ); + Properties prop = new Properties(); + prop.load(is); + + _version = prop.getProperty("app.version"); + } catch(Exception e) { + _version = "failed"; + } + } + return _version; + } +} diff --git a/src/main/java/com/tempodb/client/ClientBuilder.java b/src/main/java/com/tempodb/client/ClientBuilder.java new file mode 100644 index 0000000..d33f381 --- /dev/null +++ b/src/main/java/com/tempodb/client/ClientBuilder.java @@ -0,0 +1,88 @@ +package com.tempodb.client; + +/** + * A builder object for a Client instance. + *

+ * Typical use: + *

+ *

+ *  {@code
+ *  Client client = new ClientBuilder()
+ *      .key("your-api-key")
+ *      .secret("your-api-secret")
+ *      .host("api.tempo-db.com")
+ *      .port(80)
+ *      .secure(true)
+ *      .build();
+ *  }
+ *  
+ */ +public class ClientBuilder { + + private String key; + private String secret; + private String host = "api.tempo-db.com"; + private int port = 443; + private boolean secure = true; + + public ClientBuilder() { } + + /** + * Returns the built Client instance + * + * @return A new Client instance + */ + public Client build() { + return new Client(key, secret, host, port, secure); + } + + /** + * Sets the api key for the client instance. + * + * @param key The api key for the database being accessed + */ + public ClientBuilder key(String key) { + this.key = key; + return this; + } + + /** + * Sets the api secret for the client instance. + * + * @param secret The api secret for the database being accessed + */ + public ClientBuilder secret(String secret) { + this.secret = secret; + return this; + } + + /** + * Sets the api host for the client instance. + * + * @param host The hostname of the server being accessed + */ + public ClientBuilder host(String host) { + this.host = host; + return this; + } + + /** + * Sets the api port for the client instance. + * + * @param port The port of the server being accessed + */ + public ClientBuilder port(int port) { + this.port = port; + return this; + } + + /** + * Sets the protocol being used. + * + * @param secure true = https, false = http + */ + public ClientBuilder secure(boolean secure) { + this.secure = secure; + return this; + } +} diff --git a/src/main/java/com/tempodb/examples/ExampleBulkIncrement.java b/src/main/java/com/tempodb/examples/ExampleBulkIncrement.java new file mode 100644 index 0000000..adbff25 --- /dev/null +++ b/src/main/java/com/tempodb/examples/ExampleBulkIncrement.java @@ -0,0 +1,32 @@ +package com.tempodb.examples; + +import java.util.ArrayList; + +import org.joda.time.DateTime; + +import com.tempodb.client.Client; +import com.tempodb.client.ClientBuilder; +import com.tempodb.models.BulkDataSet; +import com.tempodb.models.BulkPoint; +import com.tempodb.models.BulkIdPoint; +import com.tempodb.models.BulkKeyPoint; + + +public class ExampleBulkIncrement { + + public static void main(String[] args) throws Exception { + Client client = new ClientBuilder() + .key("your-api-key") + .secret("your-api-secret") + .build(); + + DateTime ts = new DateTime(2012, 7, 4, 15, 2, 0, 0); + + ArrayList points = new ArrayList(); + points.add(new BulkKeyPoint("increment.java.1", 123.6)); + points.add(new BulkKeyPoint("increment.java.2", 3.4)); + + BulkDataSet dataset = new BulkDataSet(ts, points); + client.bulkWrite(dataset); + } +} diff --git a/src/main/java/com/tempodb/examples/ExampleBulkWrite.java b/src/main/java/com/tempodb/examples/ExampleBulkWrite.java new file mode 100644 index 0000000..b1cb6dd --- /dev/null +++ b/src/main/java/com/tempodb/examples/ExampleBulkWrite.java @@ -0,0 +1,32 @@ +package com.tempodb.examples; + +import java.util.ArrayList; + +import org.joda.time.DateTime; + +import com.tempodb.client.Client; +import com.tempodb.client.ClientBuilder; +import com.tempodb.models.BulkDataSet; +import com.tempodb.models.BulkPoint; +import com.tempodb.models.BulkIdPoint; +import com.tempodb.models.BulkKeyPoint; + + +public class ExampleBulkWrite { + + public static void main(String[] args) throws Exception { + Client client = new ClientBuilder() + .key("your-api-key") + .secret("your-api-secret") + .build(); + + DateTime ts = new DateTime(2012, 3, 30, 1, 0, 0, 0); + + ArrayList points = new ArrayList(); + points.add(new BulkKeyPoint("myagley-1", 123.6)); + points.add(new BulkKeyPoint("myagley-2", 3.4)); + + BulkDataSet dataset = new BulkDataSet(ts, points); + client.bulkWrite(dataset); + } +} diff --git a/src/main/java/com/tempodb/examples/ExampleCreateSeries.java b/src/main/java/com/tempodb/examples/ExampleCreateSeries.java new file mode 100644 index 0000000..c09f46f --- /dev/null +++ b/src/main/java/com/tempodb/examples/ExampleCreateSeries.java @@ -0,0 +1,22 @@ +package com.tempodb.examples; + +import com.tempodb.client.Client; +import com.tempodb.client.ClientBuilder; +import com.tempodb.models.Series; + + +public class ExampleCreateSeries { + + public static void main(String[] args) throws Exception { + Client client = new ClientBuilder() + .key("your-api-key") + .secret("your-api-secret") + .build(); + + Series series1 = client.createSeries("my-custom-key"); + Series series2 = client.createSeries(); + + System.out.println(series1); + System.out.println(series2); + } +} diff --git a/src/main/java/com/tempodb/examples/ExampleFilter.java b/src/main/java/com/tempodb/examples/ExampleFilter.java new file mode 100644 index 0000000..9d8535f --- /dev/null +++ b/src/main/java/com/tempodb/examples/ExampleFilter.java @@ -0,0 +1,23 @@ +package com.tempodb.examples; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.tempodb.models.Filter; + + +public class ExampleFilter { + + public static void main(String[] args) throws Exception { + Filter filter = new Filter(); + filter.addId("id1"); + filter.addId("id2"); + filter.addKey("key2"); + filter.addTag("tag343"); + filter.addAttribute("hello", "world"); + + System.out.println(filter); + } +} diff --git a/src/main/java/com/tempodb/examples/ExampleIncrement.java b/src/main/java/com/tempodb/examples/ExampleIncrement.java new file mode 100644 index 0000000..2a9c6d6 --- /dev/null +++ b/src/main/java/com/tempodb/examples/ExampleIncrement.java @@ -0,0 +1,37 @@ +package com.tempodb.examples; + +import java.util.ArrayList; + +import org.joda.time.DateTime; + +import com.tempodb.client.Client; +import com.tempodb.client.ClientBuilder; +import com.tempodb.models.DataPoint; +import com.tempodb.models.DataSet; + + +public class ExampleIncrement { + + public static void main(String[] args) throws Exception { + Client client = new ClientBuilder() + .key("your-api-key") + .secret("your-api-secret") + .build(); + + String key = "increment-java"; + + ArrayList datapoints = new ArrayList(); + datapoints.add(new DataPoint(new DateTime(2012, 7, 4, 15, 0, 0, 0), 1)); + datapoints.add(new DataPoint(new DateTime(2012, 7, 4, 15, 1, 0, 0), 2)); + + client.incrementKey(key, datapoints); + + DateTime start = new DateTime(2012, 7, 4, 0, 0, 0, 0); + DateTime end = new DateTime(2012, 7, 5, 0, 0, 0, 0); + + DataSet dataset = client.readKey(key, start, end); + + System.out.println(dataset); + System.out.println(dataset.getData()); + } +} diff --git a/src/main/java/com/tempodb/examples/ExampleJson.java b/src/main/java/com/tempodb/examples/ExampleJson.java new file mode 100644 index 0000000..3034e6c --- /dev/null +++ b/src/main/java/com/tempodb/examples/ExampleJson.java @@ -0,0 +1,29 @@ +package com.tempodb.examples; + +import java.util.ArrayList; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.joda.JodaModule; + +import com.tempodb.models.DataPoint; +import com.tempodb.models.DataSet; + + +public class ExampleJson { + + public static void main(String[] args) throws Exception { + + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JodaModule()); + + String json = "{\"series\":{\"id\":\"9e40006140ab4cf6a07495fe41d00a0a\",\"key\":\"myagley-1\",\"name\":\"\",\"attributes\":{},\"tags\":[]},\"start\":\"2013-01-01T06:00:00.000+0000\",\"end\":\"2013-01-02T06:00:00.000+0000\",\"data\":[],\"summary\":{\"sum\":0,\"mean\":0,\"max\":0,\"min\":0,\"count\":0}}"; + DataSet dataset = mapper.readValue(json, DataSet.class); + System.out.println(dataset); + System.out.println(dataset.getSeries()); + System.out.println(dataset.getStart()); + System.out.println(dataset.getEnd()); + System.out.println(dataset.getData()); + System.out.println(dataset.getSummary()); + } +} diff --git a/src/main/java/com/tempodb/examples/ExampleJsonBulkWrite.java b/src/main/java/com/tempodb/examples/ExampleJsonBulkWrite.java new file mode 100644 index 0000000..bf7266b --- /dev/null +++ b/src/main/java/com/tempodb/examples/ExampleJsonBulkWrite.java @@ -0,0 +1,37 @@ +package com.tempodb.examples; + +import java.util.ArrayList; + +import org.joda.time.DateTime; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.joda.JodaModule; + +import com.tempodb.models.BulkDataSet; +import com.tempodb.models.BulkPoint; +import com.tempodb.models.BulkIdPoint; +import com.tempodb.models.BulkKeyPoint; +import com.tempodb.models.DataPoint; +import com.tempodb.models.DataSet; + + +public class ExampleJsonBulkWrite { + + public static void main(String[] args) throws Exception { + + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JodaModule()); + mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + + DateTime now = new DateTime(); + ArrayList points = new ArrayList(); + points.add(new BulkKeyPoint("myagley-1", 123.6)); + points.add(new BulkIdPoint("id12121", 3)); + + BulkDataSet dataset = new BulkDataSet(now, points); + String json = mapper.writeValueAsString(dataset); + System.out.println(json); + } +} diff --git a/src/main/java/com/tempodb/examples/ExampleJsonSer.java b/src/main/java/com/tempodb/examples/ExampleJsonSer.java new file mode 100644 index 0000000..dbf70ff --- /dev/null +++ b/src/main/java/com/tempodb/examples/ExampleJsonSer.java @@ -0,0 +1,31 @@ +package com.tempodb.examples; + +import java.util.ArrayList; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.joda.JodaModule; + +import org.joda.time.DateTime; + +import com.tempodb.models.DataPoint; +import com.tempodb.models.DataSet; + + +public class ExampleJsonSer { + + public static void main(String[] args) throws Exception { + + ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JodaModule()); + mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + + ArrayList datapoints = new ArrayList(); + datapoints.add(new DataPoint(new DateTime(2012, 3, 29, 1, 0, 0, 0), 12.34)); + datapoints.add(new DataPoint(new DateTime(2012, 3, 29, 2, 0, 0, 0), 56.34)); + + String json = mapper.writeValueAsString(datapoints); + System.out.println(json); + } +} diff --git a/src/main/java/com/tempodb/examples/ExampleRead.java b/src/main/java/com/tempodb/examples/ExampleRead.java new file mode 100644 index 0000000..fa2c672 --- /dev/null +++ b/src/main/java/com/tempodb/examples/ExampleRead.java @@ -0,0 +1,33 @@ +package com.tempodb.examples; + +import java.util.List; + +import org.joda.time.DateTime; + +import com.tempodb.client.Client; +import com.tempodb.client.ClientBuilder; +import com.tempodb.models.DataSet; +import com.tempodb.models.Filter; + + +public class ExampleRead { + + public static void main(String[] args) throws Exception { + Client client = new ClientBuilder() + .key("your-api-key") + .secret("your-api-secret") + .build(); + + DateTime start = new DateTime(2012, 3, 30, 0, 0, 0, 0); + DateTime end = new DateTime(2012, 4, 1, 0, 0, 0, 0); + Filter filter = new Filter(); + filter.addKey("myagley-1"); + filter.addKey("myagley-2"); + + List datasets = client.read(start, end, filter); + + System.out.println(datasets); + System.out.println(datasets.get(0).getData()); + System.out.println(datasets.get(1).getData()); + } +} diff --git a/src/main/java/com/tempodb/examples/ExampleUpdateSeries.java b/src/main/java/com/tempodb/examples/ExampleUpdateSeries.java new file mode 100644 index 0000000..8aa8bf0 --- /dev/null +++ b/src/main/java/com/tempodb/examples/ExampleUpdateSeries.java @@ -0,0 +1,36 @@ +package com.tempodb.examples; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +import com.tempodb.client.Client; +import com.tempodb.client.ClientBuilder; +import com.tempodb.models.Filter; +import com.tempodb.models.Series; + + +public class ExampleUpdateSeries { + + public static void main(String[] args) throws Exception { + Client client = new ClientBuilder() + .key("your-api-key") + .secret("your-api-secret") + .build(); + + ArrayList tags = new ArrayList(); + tags.add("temp"); + + HashMap attributes = new HashMap(); + attributes.put("hello", "world"); + + Series series = new Series("aa798fb066da4bc28f31eaa004d3ca34", "myagley-1", "Test", tags, attributes); + client.updateSeries(series); + + Filter filter = new Filter(); + filter.addKey("myagley-1"); + + List seriesList = client.getSeries(filter); + System.out.println(seriesList); + } +} diff --git a/src/main/java/com/tempodb/examples/ExampleWrite.java b/src/main/java/com/tempodb/examples/ExampleWrite.java new file mode 100644 index 0000000..ab2c0d1 --- /dev/null +++ b/src/main/java/com/tempodb/examples/ExampleWrite.java @@ -0,0 +1,35 @@ +package com.tempodb.examples; + +import java.util.ArrayList; + +import org.joda.time.DateTime; + +import com.tempodb.client.Client; +import com.tempodb.client.ClientBuilder; +import com.tempodb.models.DataPoint; +import com.tempodb.models.DataSet; + + +public class ExampleWrite { + + public static void main(String[] args) throws Exception { + Client client = new ClientBuilder() + .key("your-api-key") + .secret("your-api-secret") + .build(); + + ArrayList datapoints = new ArrayList(); + datapoints.add(new DataPoint(new DateTime(2012, 3, 29, 5, 0, 0, 0), 32.34)); + datapoints.add(new DataPoint(new DateTime(2012, 3, 29, 6, 0, 0, 0), 36.34)); + + client.writeKey("myagley-1", datapoints); + + DateTime start = new DateTime(2012, 3, 28, 0, 0, 0, 0); + DateTime end = new DateTime(2012, 3, 31, 0, 0, 0, 0); + + DataSet dataset = client.readKey("myagley-1", start, end); + + System.out.println(dataset); + System.out.println(dataset.getData()); + } +} diff --git a/src/main/java/com/tempodb/http/PageLinks.java b/src/main/java/com/tempodb/http/PageLinks.java deleted file mode 100644 index e09c995..0000000 --- a/src/main/java/com/tempodb/http/PageLinks.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.tempodb.http; - -import org.apache.http.Header; -import org.apache.http.HttpResponse; - - -public class PageLinks { - - private static final String HEADER_LINK = "Link"; - - private static final String META_REL = "rel"; - - private static final String META_NEXT = "next"; - - private static final String DELIM_LINKS = ","; - - private static final String DELIM_LINK_PARAM = ";"; - - private String next = ""; - - public PageLinks(HttpResponse response) { - Header linkHeader = response.getFirstHeader(HEADER_LINK); - if(linkHeader != null) { - String[] links = linkHeader.getValue().split(DELIM_LINKS); - for(String link : links) { - String[] segments = link.split(DELIM_LINK_PARAM); - if(segments.length < 2) { - continue; - } - - String linkPart = segments[0].trim(); - if(!linkPart.startsWith("<") || !linkPart.endsWith(">")) { - continue; - } - linkPart = linkPart.substring(1, linkPart.length() - 1); - - for(int i = 1; i < segments.length; i++) { - String rel[] = segments[i].trim().split("="); - if(rel.length < 2 || !META_REL.equals(rel[0])) { - continue; - } - - String relValue = rel[1]; - if(relValue.startsWith("\"") && relValue.endsWith("\"")) { - relValue = relValue.substring(1, relValue.length() - 1); - } - - if(META_NEXT.equals(relValue)) { - next = linkPart; - } - } - } - } - } - - public String getNext() { - return next; - } -} diff --git a/src/main/java/com/tempodb/json/DataPointFoundSegmentModule.java b/src/main/java/com/tempodb/json/DataPointFoundSegmentModule.java deleted file mode 100644 index a6faf82..0000000 --- a/src/main/java/com/tempodb/json/DataPointFoundSegmentModule.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.List; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.deser.Deserializers; -import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; - -import org.joda.time.DateTimeZone; -import com.tempodb.DataPointFound; -import com.tempodb.DataPointFoundSegment; -import com.tempodb.Predicate; - - -public class DataPointFoundSegmentModule extends SimpleModule { - - public DataPointFoundSegmentModule() { - addDeserializer(DataPointFoundSegment.class, new DataPointFoundSegmentDeserializer()); - } - - private static class DataPointFoundSegmentDeserializer extends StdScalarDeserializer { - public DataPointFoundSegmentDeserializer() { super(DataPointFoundSegment.class); } - - @Override - public DataPointFoundSegment deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { - JsonNode root = parser.readValueAsTree(); - JsonNode tzNode = root.get("tz"); - JsonNode dataNode = root.get("data"); - JsonNode predicateNode = root.get("predicate"); - - if(tzNode == null) { - throw context.mappingException("Missing 'tz' field in DataPointFoundSegment."); - } - if(dataNode == null) { - throw context.mappingException("Missing 'data' field in DataPointFoundSegment."); - } - - DateTimeZone timezone = Json.getObjectMapper() - .reader() - .withType(DateTimeZone.class) - .readValue(tzNode); - List data = Json.getObjectMapper() - .reader() - .with(timezone.toTimeZone()) - .withType(new TypeReference>() {}) - .readValue(dataNode); - - Predicate predicate = null; - if(predicateNode != null) { - predicate = Json.getObjectMapper() - .reader() - .withType(Predicate.class) - .readValue(predicateNode); - } - - return new DataPointFoundSegment(data, timezone, predicate); - } - } - - @Override - public String getModuleName() { - return "datapointfound-segment"; - } - - @Override - public Version version() { - return Version.unknownVersion(); - } -} diff --git a/src/main/java/com/tempodb/json/DataPointSegmentModule.java b/src/main/java/com/tempodb/json/DataPointSegmentModule.java deleted file mode 100644 index cba068b..0000000 --- a/src/main/java/com/tempodb/json/DataPointSegmentModule.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.List; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.deser.Deserializers; -import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; - -import org.joda.time.DateTimeZone; -import com.tempodb.DataPoint; -import com.tempodb.DataPointSegment; -import com.tempodb.Rollup; - - -public class DataPointSegmentModule extends SimpleModule { - - public DataPointSegmentModule() { - addDeserializer(DataPointSegment.class, new DataPointSegmentDeserializer()); - } - - private static class DataPointSegmentDeserializer extends StdScalarDeserializer { - public DataPointSegmentDeserializer() { super(DataPointSegment.class); } - - @Override - public DataPointSegment deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { - JsonNode root = parser.readValueAsTree(); - JsonNode tzNode = root.get("tz"); - JsonNode dataNode = root.get("data"); - JsonNode rollupNode = root.get("rollup"); - - if(tzNode == null) { - throw context.mappingException("Missing 'tz' field in DataPointSegment."); - } - if(dataNode == null) { - throw context.mappingException("Missing 'data' field in DataPointSegment."); - } - - DateTimeZone timezone = Json.getObjectMapper() - .reader() - .withType(DateTimeZone.class) - .readValue(tzNode); - List data = Json.getObjectMapper() - .reader() - .with(timezone.toTimeZone()) - .withType(new TypeReference>() {}) - .readValue(dataNode); - - Rollup rollup = null; - if(rollupNode != null) { - rollup = Json.getObjectMapper() - .reader() - .withType(Rollup.class) - .readValue(rollupNode); - } - - return new DataPointSegment(data, timezone, rollup); - } - } - - @Override - public String getModuleName() { - return "datapoint-segment"; - } - - @Override - public Version version() { - return Version.unknownVersion(); - } -} diff --git a/src/main/java/com/tempodb/json/DateTimeZoneModule.java b/src/main/java/com/tempodb/json/DateTimeZoneModule.java deleted file mode 100644 index 76af830..0000000 --- a/src/main/java/com/tempodb/json/DateTimeZoneModule.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.deser.Deserializers; -import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; -import org.joda.time.DateTimeZone; - - -public class DateTimeZoneModule extends SimpleModule { - public DateTimeZoneModule() { - addDeserializer(DateTimeZone.class, new DateTimeZoneDeserializer()); - addSerializer(DateTimeZone.class, new DateTimeZoneSerializer()); - } - - private static class DateTimeZoneDeserializer extends StdScalarDeserializer { - public DateTimeZoneDeserializer() { super(DateTimeZone.class); } - - @Override - public DateTimeZone deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JsonProcessingException { - if (jsonParser.getCurrentToken() == JsonToken.VALUE_STRING) { - String tz = jsonParser.getText(); - return DateTimeZone.forID(tz); - } - throw deserializationContext.mappingException("Expected JSON String"); - } - } - - private static class DateTimeZoneSerializer extends StdScalarSerializer { - public DateTimeZoneSerializer() { super(DateTimeZone.class); } - - public void serialize(DateTimeZone value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { - String tz = value.getID(); - jgen.writeString(tz); - } - } - - @Override - public String getModuleName() { - return "datetimezone"; - } - - @Override - public Version version() { - return Version.unknownVersion(); - } -} diff --git a/src/main/java/com/tempodb/json/FoldModule.java b/src/main/java/com/tempodb/json/FoldModule.java deleted file mode 100644 index 1b946c1..0000000 --- a/src/main/java/com/tempodb/json/FoldModule.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.deser.Deserializers; -import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; - -import com.tempodb.Fold; - - -public class FoldModule extends SimpleModule { - public FoldModule() { - addDeserializer(Fold.class, new FoldDeserializer()); - addSerializer(Fold.class, new FoldSerializer()); - } - - private static class FoldDeserializer extends StdScalarDeserializer { - private final Fold[] constants; - private final List acceptedValues; - - public FoldDeserializer() { - super(Fold.class); - this.constants = Fold.values(); - this.acceptedValues = new ArrayList(); - for (Fold constant : constants) { - acceptedValues.add(constant.name()); - } - } - - @Override - public Fold deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { - final String text = jp.getText().toUpperCase(); - for (Fold constant : constants) { - if (constant.name().equals(text)) { - return constant; - } - } - - throw ctxt.mappingException(text + " was not one of " + acceptedValues); - } - } - - private static class FoldSerializer extends StdScalarSerializer { - public FoldSerializer() { super(Fold.class); } - - @Override - public void serialize(Fold value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { - String e = value.name().toLowerCase(); - jgen.writeString(e); - } - } - - @Override - public String getModuleName() { - return "fold"; - } - - @Override - public Version version() { - return Version.unknownVersion(); - } -} diff --git a/src/main/java/com/tempodb/json/IntervalModule.java b/src/main/java/com/tempodb/json/IntervalModule.java deleted file mode 100644 index 57959c2..0000000 --- a/src/main/java/com/tempodb/json/IntervalModule.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.TimeZone; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.deser.Deserializers; -import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; - - -public class IntervalModule extends SimpleModule { - - public IntervalModule() { - addDeserializer(Interval.class, new IntervalDeserializer()); - } - - private static class IntervalDeserializer extends StdScalarDeserializer { - public IntervalDeserializer() { super(Interval.class); } - - @Override - public Interval deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { - DateTimeZone timezone = DateTimeZone.forTimeZone(context.getTimeZone()); - Map obj = parser.readValueAs(new TypeReference>() {}); - - String startStr = obj.get("start"); - String endStr = obj.get("end"); - - if(startStr == null) { - throw context.mappingException("Missing 'start' field in Interval."); - } - if(endStr == null) { - throw context.mappingException("Missing 'end' field in Interval."); - } - - DateTime start = datetimeFromString(startStr, timezone, context); - DateTime end = datetimeFromString(endStr, timezone, context); - return new Interval(start, end); - } - } - - private static DateTime datetimeFromString(String str, DateTimeZone dtz, DeserializationContext ctxt) { - if (str.length() == 0) { // [JACKSON-360] - return null; - } - if (ctxt.isEnabled(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)) - return new DateTime(str, dtz); - else - return DateTime.parse(str); - } - - @Override - public String getModuleName() { - return "interval"; - } - - @Override - public Version version() { - return Version.unknownVersion(); - } -} diff --git a/src/main/java/com/tempodb/json/Json.java b/src/main/java/com/tempodb/json/Json.java deleted file mode 100644 index 0bbf6c1..0000000 --- a/src/main/java/com/tempodb/json/Json.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.ObjectReader; -import com.fasterxml.jackson.databind.ObjectWriter; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.datatype.joda.JodaModule; -import org.joda.time.DateTimeZone; - - -public class Json { - private Json() { /* singleton */ } - - private static ObjectMapper mapper; - - protected static ObjectMapper getObjectMapper() { - if(mapper == null) { - final ObjectMapper _mapper = new ObjectMapper(); - _mapper.registerModule(new JodaModule()); - _mapper.registerModule(new DateTimeZoneModule()); - _mapper.registerModule(new FoldModule()); - _mapper.registerModule(new DataPointSegmentModule()); - _mapper.registerModule(new DataPointFoundSegmentModule()); - _mapper.registerModule(new IntervalModule()); - _mapper.registerModule(new MultiDataPointSegmentModule()); - _mapper.registerModule(new MultiRollupDataPointSegmentModule()); - _mapper.registerModule(new SeriesSegmentModule()); - _mapper.registerModule(new SingleValueModule()); - _mapper.registerModule(new SingleValueSegmentModule()); - _mapper.registerModule(new SummaryModule()); - _mapper.registerModule(new WritableDataPointModule()); - _mapper.registerModule(new WriteRequestModule()); - _mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); - _mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - mapper = _mapper; - } - return mapper; - } - - public static T loads(String src, Class valueType) throws IOException { - return reader().withType(valueType).readValue(src); - } - - public static T loads(String src, TypeReference valueType) throws IOException { - return reader().withType(valueType).readValue(src); - } - - public static T loads(String src, Class valueType, DateTimeZone timezone) throws IOException { - return reader(timezone).withType(valueType).readValue(src); - } - - public static T loads(String src, TypeReference valueType, DateTimeZone timezone) throws IOException { - return reader(timezone).withType(valueType).readValue(src); - } - - public static ObjectReader reader() { - return getObjectMapper().reader(); - } - - public static ObjectReader reader(DateTimeZone timezone) { - return reader().with(timezone.toTimeZone()); - } - - public static ObjectWriter writer() { - return getObjectMapper().writer(); - } - - public static ObjectWriter writer(DateTimeZone timezone) { - return writer().with(timezone.toTimeZone()); - } - - public static String dumps(Object value) throws JsonProcessingException { - return writer().writeValueAsString(value); - } - - public static String dumps(Object value, DateTimeZone timezone) throws JsonProcessingException { - return writer(timezone).writeValueAsString(value); - } -} diff --git a/src/main/java/com/tempodb/json/MultiDataPointSegmentModule.java b/src/main/java/com/tempodb/json/MultiDataPointSegmentModule.java deleted file mode 100644 index 750f5c1..0000000 --- a/src/main/java/com/tempodb/json/MultiDataPointSegmentModule.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.List; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.deser.Deserializers; -import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; - -import org.joda.time.DateTimeZone; -import com.tempodb.MultiDataPoint; -import com.tempodb.MultiDataPointSegment; -import com.tempodb.Rollup; - - -public class MultiDataPointSegmentModule extends SimpleModule { - - public MultiDataPointSegmentModule() { - addDeserializer(MultiDataPointSegment.class, new MultiDataPointSegmentDeserializer()); - } - - private static class MultiDataPointSegmentDeserializer extends StdScalarDeserializer { - public MultiDataPointSegmentDeserializer() { super(MultiDataPointSegment.class); } - - @Override - public MultiDataPointSegment deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { - JsonNode root = parser.readValueAsTree(); - JsonNode tzNode = root.get("tz"); - JsonNode dataNode = root.get("data"); - JsonNode rollupNode = root.get("rollup"); - - if(tzNode == null) { - throw context.mappingException("Missing 'tz' field in MultiDataPointSegment."); - } - if(dataNode == null) { - throw context.mappingException("Missing 'data' field in MultiDataPointSegment."); - } - - DateTimeZone timezone = Json.getObjectMapper() - .reader() - .withType(DateTimeZone.class) - .readValue(tzNode); - List data = Json.getObjectMapper() - .reader() - .with(timezone.toTimeZone()) - .withType(new TypeReference>() {}) - .readValue(dataNode); - - Rollup rollup = null; - if(rollupNode != null) { - rollup = Json.getObjectMapper() - .reader() - .withType(Rollup.class) - .readValue(rollupNode); - } - - return new MultiDataPointSegment(data, timezone, rollup); - } - } - - @Override - public String getModuleName() { - return "multidatapoint-segment"; - } - - @Override - public Version version() { - return Version.unknownVersion(); - } -} diff --git a/src/main/java/com/tempodb/json/MultiRollupDataPointSegmentModule.java b/src/main/java/com/tempodb/json/MultiRollupDataPointSegmentModule.java deleted file mode 100644 index ede392b..0000000 --- a/src/main/java/com/tempodb/json/MultiRollupDataPointSegmentModule.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.List; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.deser.Deserializers; -import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; - -import org.joda.time.DateTimeZone; -import com.tempodb.MultiDataPoint; -import com.tempodb.MultiRollup; -import com.tempodb.MultiRollupDataPointSegment; - - -public class MultiRollupDataPointSegmentModule extends SimpleModule { - - public MultiRollupDataPointSegmentModule() { - addDeserializer(MultiRollupDataPointSegment.class, new MultiRollupDataPointSegmentDeserializer()); - } - - private static class MultiRollupDataPointSegmentDeserializer extends StdScalarDeserializer { - public MultiRollupDataPointSegmentDeserializer() { super(MultiRollupDataPointSegment.class); } - - @Override - public MultiRollupDataPointSegment deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { - JsonNode root = parser.readValueAsTree(); - JsonNode tzNode = root.get("tz"); - JsonNode dataNode = root.get("data"); - JsonNode rollupNode = root.get("rollup"); - - if(tzNode == null) { - throw context.mappingException("Missing 'tz' field in MultiRollupDataPointSegment."); - } - if(dataNode == null) { - throw context.mappingException("Missing 'data' field in MultiRollupDataPointSegment."); - } - if(rollupNode == null) { - throw context.mappingException("Missing 'rollup' field in MultiRollupDataPointSegment."); - } - - DateTimeZone timezone = Json.getObjectMapper() - .reader() - .withType(DateTimeZone.class) - .readValue(tzNode); - List data = Json.getObjectMapper() - .reader() - .with(timezone.toTimeZone()) - .withType(new TypeReference>() {}) - .readValue(dataNode); - - MultiRollup rollup = Json.getObjectMapper() - .reader() - .withType(MultiRollup.class) - .readValue(rollupNode); - - return new MultiRollupDataPointSegment(data, timezone, rollup); - } - } - - @Override - public String getModuleName() { - return "multirollup-datapoint-segment"; - } - - @Override - public Version version() { - return Version.unknownVersion(); - } -} diff --git a/src/main/java/com/tempodb/json/SeriesSegmentModule.java b/src/main/java/com/tempodb/json/SeriesSegmentModule.java deleted file mode 100644 index f53c758..0000000 --- a/src/main/java/com/tempodb/json/SeriesSegmentModule.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.List; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.deser.Deserializers; -import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; - -import com.tempodb.Series; -import com.tempodb.SeriesSegment; - - -public class SeriesSegmentModule extends SimpleModule { - - public SeriesSegmentModule() { - addDeserializer(SeriesSegment.class, new SeriesSegmentDeserializer()); - } - - private static class SeriesSegmentDeserializer extends StdScalarDeserializer { - public SeriesSegmentDeserializer() { super(SeriesSegment.class); } - - @Override - public SeriesSegment deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { - if(parser.getCurrentToken() == JsonToken.START_ARRAY) { - List series = parser.readValueAs(new TypeReference>() {}); - return new SeriesSegment(series); - } - throw context.mappingException("Expected JSON array"); - } - } - - @Override - public String getModuleName() { - return "series-segment"; - } - - @Override - public Version version() { - return Version.unknownVersion(); - } -} diff --git a/src/main/java/com/tempodb/json/SingleValueModule.java b/src/main/java/com/tempodb/json/SingleValueModule.java deleted file mode 100644 index 88a4969..0000000 --- a/src/main/java/com/tempodb/json/SingleValueModule.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.List; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.deser.Deserializers; -import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; - -import org.joda.time.DateTimeZone; -import com.tempodb.DataPoint; -import com.tempodb.SingleValue; -import com.tempodb.Series; - - -public class SingleValueModule extends SimpleModule { - - public SingleValueModule() { - addDeserializer(SingleValue.class, new SingleValueDeserializer()); - } - - private static class SingleValueDeserializer extends StdScalarDeserializer { - public SingleValueDeserializer() { super(SingleValue.class); } - - @Override - public SingleValue deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { - JsonNode root = parser.readValueAsTree(); - JsonNode tzNode = root.get("tz"); - JsonNode dataNode = root.get("data"); - JsonNode seriesNode = root.get("series"); - - if(tzNode == null) { - throw context.mappingException("Missing 'tz' field in SingleValue."); - } - if(dataNode == null) { - throw context.mappingException("Missing 'data' field in SingleValue."); - } - if(seriesNode == null) { - throw context.mappingException("Missing 'series' field in SingleValue."); - } - - DateTimeZone timezone = Json.getObjectMapper() - .reader() - .withType(DateTimeZone.class) - .readValue(tzNode); - DataPoint datapoint = Json.getObjectMapper() - .reader() - .with(timezone.toTimeZone()) - .withType(DataPoint.class) - .readValue(dataNode); - - Series series = Json.getObjectMapper() - .reader() - .withType(Series.class) - .readValue(seriesNode); - - return new SingleValue(series, datapoint); - } - } - - @Override - public String getModuleName() { - return "singlevalue"; - } - - @Override - public Version version() { - return Version.unknownVersion(); - } -} - diff --git a/src/main/java/com/tempodb/json/SingleValueSegmentModule.java b/src/main/java/com/tempodb/json/SingleValueSegmentModule.java deleted file mode 100644 index c30d213..0000000 --- a/src/main/java/com/tempodb/json/SingleValueSegmentModule.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.List; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.deser.Deserializers; -import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; - -import com.tempodb.SingleValue; -import com.tempodb.SingleValueSegment; - - -public class SingleValueSegmentModule extends SimpleModule { - - public SingleValueSegmentModule() { - addDeserializer(SingleValueSegment.class, new SingleValueSegmentDeserializer()); - } - - private static class SingleValueSegmentDeserializer extends StdScalarDeserializer { - public SingleValueSegmentDeserializer() { super(SingleValueSegment.class); } - - @Override - public SingleValueSegment deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { - if(parser.getCurrentToken() == JsonToken.START_ARRAY) { - List series = parser.readValueAs(new TypeReference>() {}); - return new SingleValueSegment(series); - } - throw context.mappingException("Expected JSON array"); - } - } - - @Override - public String getModuleName() { - return "singlevalue-segment"; - } - - @Override - public Version version() { - return Version.unknownVersion(); - } -} diff --git a/src/main/java/com/tempodb/json/SummaryModule.java b/src/main/java/com/tempodb/json/SummaryModule.java deleted file mode 100644 index 5871abb..0000000 --- a/src/main/java/com/tempodb/json/SummaryModule.java +++ /dev/null @@ -1,91 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.List; -import java.util.Map; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.JsonToken; -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.deser.Deserializers; -import com.fasterxml.jackson.databind.deser.std.StdScalarDeserializer; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; - -import com.tempodb.Series; -import com.tempodb.Summary; - - -public class SummaryModule extends SimpleModule { - - public SummaryModule() { - addDeserializer(Summary.class, new SummaryDeserializer()); - } - - private static class SummaryDeserializer extends StdScalarDeserializer { - public SummaryDeserializer() { super(Summary.class); } - - @Override - public Summary deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { - JsonNode root = parser.readValueAsTree(); - JsonNode tzNode = root.get("tz"); - JsonNode dataNode = root.get("summary"); - JsonNode startNode = root.get("start"); - JsonNode endNode = root.get("end"); - JsonNode seriesNode = root.get("series"); - - if(tzNode == null) { - throw context.mappingException("Missing 'tz' field in Summary."); - } - if(dataNode == null) { - throw context.mappingException("Missing 'summary' field in Summary."); - } - if(startNode == null) { - throw context.mappingException("Missing 'start' field in Summary."); - } - if(endNode == null) { - throw context.mappingException("Missing 'end' field in Summary."); - } - if(seriesNode == null) { - throw context.mappingException("Missing 'series' field in Summary."); - } - - DateTimeZone timezone = Json.getObjectMapper() - .reader() - .withType(DateTimeZone.class) - .readValue(tzNode); - - DateTime start = new DateTime(startNode.textValue(), timezone); - DateTime end = new DateTime(endNode.textValue(), timezone); - Map data = Json.getObjectMapper() - .reader() - .withType(new TypeReference>() {}) - .readValue(dataNode); - Series series = Json.getObjectMapper() - .reader() - .withType(Series.class) - .readValue(seriesNode); - - Summary summary = new Summary(series, new Interval(start, end), data); - return summary; - } - } - - @Override - public String getModuleName() { - return "summary"; - } - - @Override - public Version version() { - return Version.unknownVersion(); - } -} - diff --git a/src/main/java/com/tempodb/json/WritableDataPointModule.java b/src/main/java/com/tempodb/json/WritableDataPointModule.java deleted file mode 100644 index 563da0c..0000000 --- a/src/main/java/com/tempodb/json/WritableDataPointModule.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; - -import com.tempodb.WritableDataPoint; - - -public class WritableDataPointModule extends SimpleModule { - public WritableDataPointModule() { - addSerializer(WritableDataPoint.class, new WritableDataPointSerializer()); - } - - private static class WritableDataPointSerializer extends StdScalarSerializer { - public WritableDataPointSerializer() { super(WritableDataPoint.class); } - - @Override - public void serialize(WritableDataPoint value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { - jgen.writeStartObject(); - jgen.writeStringField("key", value.getSeries().getKey()); - jgen.writeObjectField("t", value.getTimestamp()); - jgen.writeObjectField("v", value.getValue()); - jgen.writeEndObject(); - } - } - - @Override - public String getModuleName() { - return "multidatapoint"; - } - - @Override - public Version version() { - return Version.unknownVersion(); - } -} diff --git a/src/main/java/com/tempodb/json/WriteRequestModule.java b/src/main/java/com/tempodb/json/WriteRequestModule.java deleted file mode 100644 index 04c6f8f..0000000 --- a/src/main/java/com/tempodb/json/WriteRequestModule.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; - -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.core.Version; -import com.fasterxml.jackson.databind.*; -import com.fasterxml.jackson.databind.module.SimpleModule; -import com.fasterxml.jackson.databind.ser.std.StdScalarSerializer; - -import com.tempodb.WriteRequest; - - -public class WriteRequestModule extends SimpleModule { - public WriteRequestModule() { - addSerializer(WriteRequest.class, new WriteRequestSerializer()); - } - - private static class WriteRequestSerializer extends StdScalarSerializer { - public WriteRequestSerializer() { super(WriteRequest.class); } - - @Override - public void serialize(WriteRequest value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { - jgen.writeObject(value.iterator()); - } - } - - @Override - public String getModuleName() { - return "write-request"; - } - - @Override - public Version version() { - return Version.unknownVersion(); - } -} diff --git a/src/main/java/com/tempodb/models/BulkDataSet.java b/src/main/java/com/tempodb/models/BulkDataSet.java new file mode 100644 index 0000000..3a693bc --- /dev/null +++ b/src/main/java/com/tempodb/models/BulkDataSet.java @@ -0,0 +1,34 @@ +package com.tempodb.models; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.joda.time.DateTime; + + +/** + * Set of data to send for a bulk write. This encapsulates the timestamp and list of BulkPoints + */ +public class BulkDataSet { + private final DateTime timestamp; + private final List data; + + /** + * @param timestamp The timestamp to write the datapoints at + * @param data A list of BulkPoints to write + */ + @JsonCreator + public BulkDataSet(@JsonProperty("t") DateTime timestamp, @JsonProperty("data") List data) { + this.timestamp = timestamp; + this.data = data; + } + + @JsonProperty("t") + public DateTime getTimestamp() { return timestamp; } + + @JsonProperty("data") + public List getData() { return data; } + +} diff --git a/src/main/java/com/tempodb/models/BulkIdPoint.java b/src/main/java/com/tempodb/models/BulkIdPoint.java new file mode 100644 index 0000000..d0e45c1 --- /dev/null +++ b/src/main/java/com/tempodb/models/BulkIdPoint.java @@ -0,0 +1,25 @@ +package com.tempodb.models; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + + +/** + * Represents a datapoint for a series referenced by id. This class is used to represent + * datapoints in a bulk write. + */ +public class BulkIdPoint extends BulkPoint { + private final String id; + + /** + * @param id The id of the Series + * @param value The datapoint value + */ + @JsonCreator + public BulkIdPoint(@JsonProperty("id") String id, @JsonProperty("v") Number value) { + this.id = id; + this.value = value; + } + + public String getId() { return id; } +} diff --git a/src/main/java/com/tempodb/models/BulkKeyPoint.java b/src/main/java/com/tempodb/models/BulkKeyPoint.java new file mode 100644 index 0000000..315792d --- /dev/null +++ b/src/main/java/com/tempodb/models/BulkKeyPoint.java @@ -0,0 +1,25 @@ +package com.tempodb.models; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + + +/** + * Represents a datapoint for a series referenced by key. This class is used to represent + * datapoints in a bulk write. + */ +public class BulkKeyPoint extends BulkPoint { + private final String key; + + /** + * @param key The key of the Series + * @param value The datapoint value + */ + @JsonCreator + public BulkKeyPoint(@JsonProperty("key") String key, @JsonProperty("v") Number value) { + this.key = key; + this.value = value; + } + + public String getKey() { return key; } +} diff --git a/src/main/java/com/tempodb/models/BulkPoint.java b/src/main/java/com/tempodb/models/BulkPoint.java new file mode 100644 index 0000000..84db2f4 --- /dev/null +++ b/src/main/java/com/tempodb/models/BulkPoint.java @@ -0,0 +1,17 @@ +package com.tempodb.models; + +import com.fasterxml.jackson.annotation.JsonProperty; + + +/** + * The abstract parent class representing a datapoint used in a bulk write. Bulk + * writing allows values for different series to be written for the same timestamp in one + * Rest call. The series can be referenced by series id or series key. The two subclasses + * represent these two options. + */ +public abstract class BulkPoint { + protected Number value; + + @JsonProperty("v") + public Number getValue() { return value; } +} diff --git a/src/main/java/com/tempodb/models/DataPoint.java b/src/main/java/com/tempodb/models/DataPoint.java new file mode 100644 index 0000000..db9277d --- /dev/null +++ b/src/main/java/com/tempodb/models/DataPoint.java @@ -0,0 +1,39 @@ +package com.tempodb.models; + +import java.util.ArrayList; +import java.util.HashMap; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.joda.time.DateTime; + + +/** + * Represents one timestamp/value pair. This class uses a Joda Time DateTime. + */ +public class DataPoint { + private final DateTime timestamp; + private final Number value; + + /** + * @param timestamp A Joda Time DateTime representing the data point's timstamp + * @param value The value of the measurement (long or double) + */ + @JsonCreator + public DataPoint(@JsonProperty("t") DateTime timestamp, @JsonProperty("v") Number value) { + this.timestamp = timestamp; + this.value = value; + } + + @JsonProperty("t") + public DateTime getTimestamp() { return timestamp; } + + @JsonProperty("v") + public Number getValue() { return value; } + + @Override + public String toString() { + return String.format("DataPoint(%s, %s)", timestamp, value); + } +} diff --git a/src/main/java/com/tempodb/models/DataSet.java b/src/main/java/com/tempodb/models/DataSet.java new file mode 100644 index 0000000..9310ba7 --- /dev/null +++ b/src/main/java/com/tempodb/models/DataSet.java @@ -0,0 +1,50 @@ +package com.tempodb.models; + +import java.util.ArrayList; +import java.util.Map; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.joda.time.DateTime; + + +/** + * Respresents data from a time range of a series. This is essentially a list + * of DataPoints with some added metadata. This is the object returned from a query. + * The DataSet contains series metadata, the start/end times for the queried range, + * a list of the DataPoints and a statistics summary table. The Summary table contains + * statistics for the time range (sum, mean, min, max, count, etc.) + */ +public class DataSet { + private final Series series; + private final DateTime start; + private final DateTime end; + private final List data; + private final Map summary; + + /** + * @param series series metadata (Series) + * @param start start time for the queried range (DateTime) + * @param end end time for the queried range (DateTime) + * @param data datapoints (List of DataPoints) + * @param summary a summary table of statistics for the queried range (Map) + */ + @JsonCreator + public DataSet(@JsonProperty("series") Series series, @JsonProperty("start") DateTime start, + @JsonProperty("end") DateTime end, @JsonProperty("data") List data, + @JsonProperty("summary") Map summary) { + this.series = series; + this.start = start; + this.end = end; + this.data = data; + this.summary = summary; + } + + public Series getSeries() { return series; } + public DateTime getStart() { return start; } + public DateTime getEnd() { return end; } + public List getData() { return data; } + public Map getSummary() { return summary; } +} diff --git a/src/main/java/com/tempodb/models/Filter.java b/src/main/java/com/tempodb/models/Filter.java new file mode 100644 index 0000000..a0bc88f --- /dev/null +++ b/src/main/java/com/tempodb/models/Filter.java @@ -0,0 +1,96 @@ +package com.tempodb.models; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.http.NameValuePair; +import org.apache.http.client.utils.URLEncodedUtils; +import org.apache.http.message.BasicNameValuePair; + + +/** + * Represents a filter on the set of Series. This is used to query a set of series with specific + * properties. A filter can include ids, keys, tags and attributes. An empty filter is created + * and filter predicates are added. For example a filter to return series with keys myagley-1 and + * myagley-2 looks like this: + *
+ *  {@code
+ *  Filter filter = new Filter();
+ *  filter.addKey("myagley-1");
+ *  filter.addKey("myagley-1");
+ *  }
+ *  
+ */ +public class Filter { + private final List ids = new ArrayList(); + private final List keys = new ArrayList(); + private final List tags = new ArrayList(); + private final Map attributes = new HashMap(); + + /** + * Adds an id to the filter. + * + * @param id The id to add + */ + public synchronized void addId(String id) { ids.add(id); } + + /** + * Adds a key to the filter. + * + * @param key The key to add + */ + public synchronized void addKey(String key) { keys.add(key); } + + /** + * Adds a tag to the filter. + * + * @param tag The tag to add + */ + public synchronized void addTag(String tag) { tags.add(tag); } + + /** + * Adds an attribute to the filter. + * + * @param key The attribute key + * @param value The attribute value + */ + public synchronized void addAttribute(String key, String value) { attributes.put(key, value); } + + /** + * Returns a list of NameValuePairs in the format required for the Rest API. + * This is mainly used internally by the client. + */ + public List getParams() { + List params = new ArrayList(); + + // Add the ids + for (String id : ids) + params.add(new BasicNameValuePair("id", id)); + + // Add the keys + for (String key : keys) + params.add(new BasicNameValuePair("key", key)); + + // Add the tags + for (String tag : tags) + params.add(new BasicNameValuePair("tag", tag)); + + // Add the attributes + for (Map.Entry attribute : attributes.entrySet()) + params.add(new BasicNameValuePair(String.format("attr[%s]", attribute.getKey()), attribute.getValue())); + + return params; + } + + @Override + public String toString() { + return URLEncodedUtils.format(getParams(), "UTF-8"); + } + + public List getIds() { return ids; } + public List getKeys() { return keys; } + public List getTags() { return tags; } + public Map getAttributes() { return attributes; } +} diff --git a/src/main/java/com/tempodb/models/Series.java b/src/main/java/com/tempodb/models/Series.java new file mode 100644 index 0000000..84244b2 --- /dev/null +++ b/src/main/java/com/tempodb/models/Series.java @@ -0,0 +1,63 @@ +package com.tempodb.models; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + + +/** + * Respresents metadata associated with the series. Each series has a + * globally unique id that is generated by the system and a user defined key. + * The key must be unique among all of your series. Each series may have a set + * of tags and attributes that can be used to filter series during bulk reads. + * Attributes are key/value pairs. Both the key and attribute must be strings. + * Tags are keys with no values. Tags must also be strings. + */ +public class Series { + private final String id; + private final String key; + private final String name; + private final List tags; + private final Map attributes; + + /** + * @param id unique series id (String) + * @param key user defined key (String) + * @param name human readable name for the series (String) + * @param attributes key/value pairs providing metadata for the series (Map - keys and values are Strings) + * @param tags (List of Strings) + */ + @JsonCreator + public Series(@JsonProperty("id") String id, @JsonProperty("key") String key, + @JsonProperty("name") String name, @JsonProperty("tags") List tags, + @JsonProperty("attributes") Map attributes) { + this.id = id; + this.key = key; + this.name = name; + this.tags = tags; + this.attributes = attributes; + } + + /** + * @param id unique series id (String) + * @param key user defined key (String) + */ + public Series(String id, String key) { + this(id, key, "", new ArrayList(), new HashMap()); + } + + public String getId() { return id; } + public String getKey() { return key; } + public String getName() { return name; } + public List getTags() { return tags; } + public Map getAttributes() { return attributes; } + + @Override + public String toString() { + return String.format("Series: \n\tid:\t%s\n\tkey:\t%s\n\tname:\t%s\n\ttags:\t%s\n\tattr:\t%s", id, key, name, tags, attributes); + } +} diff --git a/src/main/java/com/tempodb/util/Preconditions.java b/src/main/java/com/tempodb/util/Preconditions.java deleted file mode 100644 index c7843db..0000000 --- a/src/main/java/com/tempodb/util/Preconditions.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.tempodb.util; - - -public final class Preconditions { - private Preconditions() {} - - public static void checkArgument(boolean expression) { - if(!expression) { - throw new IllegalArgumentException(); - } - } - - public static void checkArgument(boolean expression, Object errorMessage) { - if(!expression) { - throw new IllegalArgumentException(String.valueOf(errorMessage)); - } - } - - public static void checkArgument(boolean expression, String errorMessageTemplate, Object... errorMessageArgs) { - if(!expression) { - throw new IllegalArgumentException(format(errorMessageTemplate, errorMessageArgs)); - } - } - - public static T checkNotNull(T reference) { - if(reference == null) { - throw new NullPointerException(); - } - return reference; - } - - public static T checkNotNull(T reference, Object errorMessage) { - if (reference == null) { - throw new NullPointerException(String.valueOf(errorMessage)); - } - return reference; - } - - public static T checkNotNull(T reference, String errorMessageTemplate, Object... errorMessageArgs) { - if (reference == null) { - // If either of these parameters is null, the right thing happens anyway - throw new NullPointerException(format(errorMessageTemplate, errorMessageArgs)); - } - return reference; - } - - static String format(String template, Object... args) { - template = String.valueOf(template); - StringBuilder builder = new StringBuilder(template.length() + 16 * args.length); - int templateStart = 0; - int i = 0; - while (i < args.length) { - int placeholderStart = template.indexOf("%s", templateStart); - if (placeholderStart == -1) { - break; - } - builder.append(template.substring(templateStart, placeholderStart)); - builder.append(args[i++]); - templateStart = placeholderStart + 2; - } - builder.append(template.substring(templateStart)); - - // if we run out of placeholders, append the extra args in square braces - if (i < args.length) { - builder.append(" ["); - builder.append(args[i++]); - while (i < args.length) { - builder.append(", "); - builder.append(args[i++]); - } - builder.append(']'); - } - - return builder.toString(); - } -} diff --git a/src/main/resources/build.properties b/src/main/resources/build.properties new file mode 100644 index 0000000..001cdbc --- /dev/null +++ b/src/main/resources/build.properties @@ -0,0 +1 @@ +app.version=${project.version} diff --git a/src/test/java/com/tempodb/AggregationTest.java b/src/test/java/com/tempodb/AggregationTest.java deleted file mode 100644 index d8d8a19..0000000 --- a/src/test/java/com/tempodb/AggregationTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.tempodb; - -import org.junit.*; -import static org.junit.Assert.*; - - -public class AggregationTest { - - @Test - public void testEquals() { - Aggregation a1 = new Aggregation(Fold.SUM); - Aggregation a2 = new Aggregation(Fold.SUM); - assertEquals(a1, a2); - } - - @Test - public void testNotEquals_Fold() { - Aggregation a1 = new Aggregation(Fold.SUM); - Aggregation a2 = new Aggregation(Fold.MEAN); - assertFalse(a1.equals(a2)); - } - - @Test - public void testNotEquals_Null() { - Aggregation a1 = new Aggregation(Fold.SUM); - assertFalse(a1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/ClientBuilderTest.java b/src/test/java/com/tempodb/ClientBuilderTest.java deleted file mode 100644 index 23f0fcc..0000000 --- a/src/test/java/com/tempodb/ClientBuilderTest.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.tempodb; - -import java.net.InetSocketAddress; - -import org.junit.*; -import static org.junit.Assert.*; - - -public class ClientBuilderTest { - - private static final Database database = new Database("id"); - private static final Credentials credentials = new Credentials("key", "secret"); - - @Test - public void testDefaults() { - Client client = new ClientBuilder() - .database(database) - .credentials(credentials) - .build(); - assertEquals("api.tempo-db.com", client.getHost().getHostName()); - assertEquals(443, client.getHost().getPort()); - assertEquals("https", client.getScheme()); - } -} diff --git a/src/test/java/com/tempodb/ClientTest.java b/src/test/java/com/tempodb/ClientTest.java deleted file mode 100644 index b113f6d..0000000 --- a/src/test/java/com/tempodb/ClientTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.InetSocketAddress; - -import org.apache.http.*; -import org.apache.http.message.BasicHttpRequest; -import org.junit.*; -import static org.junit.Assert.*; -import org.junit.rules.ExpectedException; - - -public class ClientTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void testConstructor() { - Client client = new Client(new Database("id"), new Credentials("key", "secret"), new InetSocketAddress("example.com", 10), "http"); - assertNotNull(client); - } - - @Test - public void testInvalidScheme() { - thrown.expect(IllegalArgumentException.class); - Client client = new Client(new Database("id"), new Credentials("key", "secret"), new InetSocketAddress("example.com", 10), "scheme"); - } -} diff --git a/src/test/java/com/tempodb/CreateSeriesTest.java b/src/test/java/com/tempodb/CreateSeriesTest.java deleted file mode 100644 index 8759df9..0000000 --- a/src/test/java/com/tempodb/CreateSeriesTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.nio.charset.Charset; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.HashSet; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.protocol.HttpContext; -import org.apache.http.util.EntityUtils; -import org.junit.*; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; -import org.mockito.ArgumentCaptor; - - -public class CreateSeriesTest { - - private static final String json = "{\"id\":\"id1\",\"key\":\"key1\",\"name\":\"name1\",\"tags\":[],\"attributes\":{}}"; - private static final String body = "{\"key\":\"key1\",\"name\":\"name1\",\"tags\":[],\"attributes\":{}}"; - private static final Series series = new Series("key1", "name1", new HashSet(), new HashMap()); - private static final Series series1 = new Series("key1", "name1", new HashSet(), new HashMap()); - - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, json); - Client client = Util.getClient(response); - - Result result = client.createSeries(series); - - assertEquals(series1, result.getValue()); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.createSeries(series); - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("POST", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.createSeries(series); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/series/", uri.getPath()); - } - - @Test - public void testBody() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.createSeries(series); - - ArgumentCaptor argument = ArgumentCaptor.forClass(HttpPost.class); - verify(mockClient).execute(any(HttpHost.class), argument.capture(), any(HttpContext.class)); - assertEquals(body, EntityUtils.toString(argument.getValue().getEntity(), DEFAULT_CHARSET)); - } -} diff --git a/src/test/java/com/tempodb/CredentialsTest.java b/src/test/java/com/tempodb/CredentialsTest.java deleted file mode 100644 index 18d741d..0000000 --- a/src/test/java/com/tempodb/CredentialsTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.tempodb; - -import org.junit.*; -import static org.junit.Assert.*; - - -public class CredentialsTest { - - @Test - public void testEquals() { - Credentials c1 = new Credentials("key", "secret"); - Credentials c2 = new Credentials("key", "secret"); - assertEquals(c1, c2); - } - - @Test - public void testNotEquals_Key() { - Credentials c1 = new Credentials("key1", "secret"); - Credentials c2 = new Credentials("key2", "secret"); - assertFalse(c1.equals(c2)); - } - - @Test - public void testNotEquals_Secret() { - Credentials c1 = new Credentials("key", "secret1"); - Credentials c2 = new Credentials("key", "secret2"); - assertFalse(c1.equals(c2)); - } - - @Test - public void testNotEquals_Null() { - Credentials c1 = new Credentials("key", "secret"); - assertFalse(c1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/DataPointFoundSegmentTest.java b/src/test/java/com/tempodb/DataPointFoundSegmentTest.java deleted file mode 100644 index ba59ff3..0000000 --- a/src/test/java/com/tempodb/DataPointFoundSegmentTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.tempodb; - -import java.util.Arrays; -import java.util.List; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; - - -public class DataPointFoundSegmentTest { - - private static final DateTime start = new DateTime(2012, 1, 1, 0, 0, 0, 0); - private static final DateTime end1 = new DateTime(2012, 1, 1, 1, 0, 0, 0); - private static final DateTime end2 = new DateTime(2012, 1, 1, 2, 0, 0, 0); - - private static final Interval interval1 = new Interval(start, end1); - private static final Interval interval2 = new Interval(start, end1); - private static final Interval interval3 = new Interval(start, end2); - - private static final DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - private static final DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - private static final DataPoint dp3 = new DataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0), 10.34); - - private List data1 = Arrays.asList( - new DataPointFound(interval1, dp1) - ); - private List data2 = Arrays.asList( - new DataPointFound(interval2, dp2) - ); - private List data3 = Arrays.asList( - new DataPointFound(interval3, dp3) - ); - - private Predicate predicate1 = new Predicate(Period.minutes(1), "max"); - private Predicate predicate2 = new Predicate(Period.minutes(1), "max"); - private Predicate predicate3 = new Predicate(Period.minutes(2), "max"); - - private DateTimeZone zone1 = DateTimeZone.forID("UTC"); - private DateTimeZone zone2 = DateTimeZone.forID("UTC"); - private DateTimeZone zone3 = DateTimeZone.forID("America/Chicago"); - - @Test - public void testEquals() { - DataPointFoundSegment segment1 = new DataPointFoundSegment(data1, null, zone1, predicate1); - DataPointFoundSegment segment2 = new DataPointFoundSegment(data2, null, zone2, predicate2); - assertEquals(segment1, segment2); - } - - @Test - public void testNotEquals_Data() { - DataPointFoundSegment segment1 = new DataPointFoundSegment(data1, null, zone1, predicate1); - DataPointFoundSegment segment2 = new DataPointFoundSegment(data3, null, zone2, predicate2); - assertFalse(segment1.equals(segment2)); - } - - @Test - public void testNotEquals_TZ() { - DataPointFoundSegment segment1 = new DataPointFoundSegment(data1, null, zone1, predicate1); - DataPointFoundSegment segment2 = new DataPointFoundSegment(data2, null, zone3, predicate2); - assertFalse(segment1.equals(segment2)); - } - - @Test - public void testNotEquals_Predicate() { - DataPointFoundSegment segment1 = new DataPointFoundSegment(data1, null, zone1, predicate1); - DataPointFoundSegment segment2 = new DataPointFoundSegment(data2, null, zone2, predicate3); - assertFalse(segment1.equals(segment2)); - } - - @Test - public void testNotEquals_Null() { - DataPointFoundSegment segment1 = new DataPointFoundSegment(data1, null, zone1, predicate1); - assertFalse(segment1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/DataPointFoundTest.java b/src/test/java/com/tempodb/DataPointFoundTest.java deleted file mode 100644 index 5fb7b1b..0000000 --- a/src/test/java/com/tempodb/DataPointFoundTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.tempodb; - -import org.joda.time.DateTime; -import org.joda.time.Interval; -import org.junit.*; -import static org.junit.Assert.*; - - -public class DataPointFoundTest { - - private static final DateTime start = new DateTime(2012, 1, 1, 0, 0, 0, 0); - private static final DateTime end1 = new DateTime(2012, 1, 1, 1, 0, 0, 0); - private static final DateTime end2 = new DateTime(2012, 1, 1, 2, 0, 0, 0); - - private static final Interval interval1 = new Interval(start, end1); - private static final Interval interval2 = new Interval(start, end1); - private static final Interval interval3 = new Interval(start, end2); - - private static final DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - private static final DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - private static final DataPoint dp3 = new DataPoint(new DateTime(2012, 1, 1, 0, 1, 0, 0), 10.34); - - - @Test - public void testEquals() { - DataPointFound dpf1 = new DataPointFound(interval1, dp1); - DataPointFound dpf2 = new DataPointFound(interval2, dp2); - assertEquals(dpf1, dpf2); - } - - @Test - public void testNotEquals_Interval() { - DataPointFound dpf1 = new DataPointFound(interval1, dp1); - DataPointFound dpf2 = new DataPointFound(interval3, dp2); - assertFalse(dp1.equals(dpf2)); - } - - @Test - public void testNotEquals_DataPoint() { - DataPointFound dpf1 = new DataPointFound(interval1, dp1); - DataPointFound dpf2 = new DataPointFound(interval2, dp3); - assertFalse(dp1.equals(dpf2)); - } - - @Test - public void testNotEquals_Null() { - DataPointFound dpf1 = new DataPointFound(interval1, dp1); - assertFalse(dpf1.equals(null)); - } -} - diff --git a/src/test/java/com/tempodb/DataPointSegmentTest.java b/src/test/java/com/tempodb/DataPointSegmentTest.java deleted file mode 100644 index 65d5b98..0000000 --- a/src/test/java/com/tempodb/DataPointSegmentTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.tempodb; - -import java.util.Arrays; -import java.util.List; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; - - -public class DataPointSegmentTest { - - private List data1 = Arrays.asList(new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, 0, DateTimeZone.UTC), 12.34)); - private List data2 = Arrays.asList(new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, 0, DateTimeZone.UTC), 12.34)); - private List data3 = Arrays.asList(new DataPoint(new DateTime(2012, 1, 2, 0, 0, 1, 0, DateTimeZone.UTC), 12.34)); - - private Rollup rollup1 = new Rollup(Period.minutes(1), Fold.SUM); - private Rollup rollup2 = new Rollup(Period.minutes(1), Fold.SUM); - private Rollup rollup3 = new Rollup(Period.minutes(2), Fold.SUM); - - private DateTimeZone zone1 = DateTimeZone.forID("UTC"); - private DateTimeZone zone2 = DateTimeZone.forID("UTC"); - private DateTimeZone zone3 = DateTimeZone.forID("America/Chicago"); - - @Test - public void testEquals() { - DataPointSegment segment1 = new DataPointSegment(data1, null, zone1, rollup1); - DataPointSegment segment2 = new DataPointSegment(data2, null, zone2, rollup2); - assertEquals(segment1, segment2); - } - - @Test - public void testNotEquals_Data() { - DataPointSegment segment1 = new DataPointSegment(data1, null, zone1, rollup1); - DataPointSegment segment2 = new DataPointSegment(data3, null, zone2, rollup2); - assertFalse(segment1.equals(segment2)); - } - - @Test - public void testNotEquals_TZ() { - DataPointSegment segment1 = new DataPointSegment(data1, null, zone1, rollup1); - DataPointSegment segment2 = new DataPointSegment(data2, null, zone3, rollup2); - assertFalse(segment1.equals(segment2)); - } - - @Test - public void testNotEquals_Rollup() { - DataPointSegment segment1 = new DataPointSegment(data1, null, zone1, rollup1); - DataPointSegment segment2 = new DataPointSegment(data2, null, zone2, rollup3); - assertFalse(segment1.equals(segment2)); - } - - @Test - public void testNotEquals_Null() { - DataPointSegment segment1 = new DataPointSegment(data1, null, zone1, rollup1); - assertFalse(segment1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/DataPointTest.java b/src/test/java/com/tempodb/DataPointTest.java deleted file mode 100644 index 202a27f..0000000 --- a/src/test/java/com/tempodb/DataPointTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.tempodb; - -import org.joda.time.DateTime; -import org.junit.*; -import static org.junit.Assert.*; - - -public class DataPointTest { - - @Test - public void testEquals() { - DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - assertEquals(dp1, dp2); - } - - @Test - public void testNotEquals_DateTime() { - DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 2, 0, 0, 0, 0), 12.34); - assertFalse(dp1.equals(dp2)); - } - - @Test - public void testNotEquals_Value() { - DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), 12); - assertFalse(dp1.equals(dp2)); - } - - @Test - public void testNotEquals_Null() { - DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - assertFalse(dp1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/DatabaseTest.java b/src/test/java/com/tempodb/DatabaseTest.java deleted file mode 100644 index e17feee..0000000 --- a/src/test/java/com/tempodb/DatabaseTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.tempodb; - -import org.junit.*; -import static org.junit.Assert.*; - - -public class DatabaseTest { - - @Test - public void testEquals() { - Database d1 = new Database("id"); - Database d2 = new Database("id"); - assertEquals(d1, d2); - } - - @Test - public void testNotEquals_Id() { - Database d1 = new Database("id1"); - Database d2 = new Database("id2"); - assertFalse(d1.equals(d2)); - } - - @Test - public void testNotEquals_Null() { - Database d1 = new Database("id"); - assertFalse(d1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/DeleteAllSeriesTest.java b/src/test/java/com/tempodb/DeleteAllSeriesTest.java deleted file mode 100644 index 7c94eff..0000000 --- a/src/test/java/com/tempodb/DeleteAllSeriesTest.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.List; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.message.BasicNameValuePair; -import org.junit.*; -import static org.junit.Assert.*; - - -public class DeleteAllSeriesTest { - - private static final String json = "{\"deleted\":127}"; - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, json); - Client client = Util.getClient(response); - - Result result = client.deleteAllSeries(); - Result expected = new Result(new DeleteSummary(127), 200, "OK"); - assertEquals(expected, result); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.deleteAllSeries(); - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("DELETE", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.deleteAllSeries(); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/series/", uri.getPath()); - } - - @Test - public void testParameters() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.deleteAllSeries(); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("allow_truncation", "true"))); - assertEquals(1, params.size()); - } -} diff --git a/src/test/java/com/tempodb/DeleteDataPointsByKeyTest.java b/src/test/java/com/tempodb/DeleteDataPointsByKeyTest.java deleted file mode 100644 index fbfc8df..0000000 --- a/src/test/java/com/tempodb/DeleteDataPointsByKeyTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.List; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.message.BasicNameValuePair; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; -import org.junit.*; -import static org.junit.Assert.*; - - -public class DeleteDataPointsByKeyTest { - private DateTimeZone timezone = DateTimeZone.UTC; - private DateTime start = new DateTime(2012, 1, 1, 0, 0, 0, 0, timezone); - private DateTime end = new DateTime(2012, 1, 2, 0, 0, 0, 0, timezone); - private Series series = new Series("key1"); - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, ""); - Client client = Util.getClient(response); - - Result result = client.deleteDataPoints(series, new Interval(start, end)); - Result expected = new Result(null, 200, "OK"); - assertEquals(expected, result); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, ""); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.deleteDataPoints(series, new Interval(start, end)); - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("DELETE", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, ""); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.deleteDataPoints(series, new Interval(start, end)); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/series/key/key1/data/", uri.getPath()); - } - - @Test - public void testParameters() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, ""); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.deleteDataPoints(series, new Interval(start, end)); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("start", "2012-01-01T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("end", "2012-01-02T00:00:00.000+0000"))); - assertEquals(2, params.size()); - } -} diff --git a/src/test/java/com/tempodb/DeleteSeriesByFilterTest.java b/src/test/java/com/tempodb/DeleteSeriesByFilterTest.java deleted file mode 100644 index 3bb5168..0000000 --- a/src/test/java/com/tempodb/DeleteSeriesByFilterTest.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.List; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.message.BasicNameValuePair; -import org.junit.*; -import static org.junit.Assert.*; - - -public class DeleteSeriesByFilterTest { - - private static final String json = "{\"deleted\":127}"; - private static final Filter filter = new Filter(); - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, json); - Client client = Util.getClient(response); - - Result result = client.deleteSeries(filter); - Result expected = new Result(new DeleteSummary(127), 200, "OK"); - assertEquals(expected, result); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.deleteSeries(filter); - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("DELETE", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.deleteSeries(filter); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/series/", uri.getPath()); - } - - @Test - public void testParameters() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter(); - filter.addKey("key1"); - filter.addTag("tag1"); - filter.addTag("tag1"); - filter.addAttribute("key1", "value1"); - filter.addAttribute("key2", "value2"); - - Result result = client.deleteSeries(filter); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("key", "key1"))); - assertTrue(params.contains(new BasicNameValuePair("tag", "tag1"))); - assertTrue(params.contains(new BasicNameValuePair("attr[key1]", "value1"))); - assertTrue(params.contains(new BasicNameValuePair("attr[key2]", "value2"))); - assertEquals(4, params.size()); - } -} diff --git a/src/test/java/com/tempodb/DeleteSeriesTest.java b/src/test/java/com/tempodb/DeleteSeriesTest.java deleted file mode 100644 index 12c780a..0000000 --- a/src/test/java/com/tempodb/DeleteSeriesTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.junit.*; -import static org.junit.Assert.*; - - -public class DeleteSeriesTest { - private static final Series series = new Series("key1"); - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, ""); - Client client = Util.getClient(response); - - Result expected = new Result(null, 200, "OK"); - Result result = client.deleteSeries(series); - assertEquals(expected, result); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, ""); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.deleteSeries(series); - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("DELETE", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, ""); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.deleteSeries(series); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/series/key/key1/", uri.getPath()); - } -} diff --git a/src/test/java/com/tempodb/DeleteSummaryTest.java b/src/test/java/com/tempodb/DeleteSummaryTest.java deleted file mode 100644 index 00b16b6..0000000 --- a/src/test/java/com/tempodb/DeleteSummaryTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.tempodb; - -import org.junit.*; -import static org.junit.Assert.*; - - -public class DeleteSummaryTest { - - @Test - public void testEquals() { - DeleteSummary d1 = new DeleteSummary(0); - DeleteSummary d2 = new DeleteSummary(0); - assertEquals(d1, d2); - } - - @Test - public void testNotEquals() { - DeleteSummary d1 = new DeleteSummary(0); - DeleteSummary d2 = new DeleteSummary(2); - assertFalse(d1.equals(d2)); - } - - @Test - public void testNotEquals_Null() { - DeleteSummary d1 = new DeleteSummary(0); - assertFalse(d1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/FilterTest.java b/src/test/java/com/tempodb/FilterTest.java deleted file mode 100644 index 74d77cd..0000000 --- a/src/test/java/com/tempodb/FilterTest.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.tempodb; - -import java.util.HashMap; -import java.util.HashSet; - -import org.junit.*; -import static org.junit.Assert.*; - - -public class FilterTest { - - @Test - public void testEquals() { - Filter f1 = new Filter(); - Filter f2 = new Filter(); - - f1.addTag("tag"); - f2.addTag("tag"); - - f1.addAttribute("key", "value"); - f2.addAttribute("key", "value"); - - assertEquals(f1, f2); - } - - @Test - public void testNotEquals_Keys() { - Filter f1 = new Filter(); - Filter f2 = new Filter(); - f1.addKey("key1"); - f1.addKey("key2"); - assertFalse(f1.equals(f2)); - } - - @Test - public void testNotEquals_Tags() { - Filter f1 = new Filter(); - Filter f2 = new Filter(); - f1.addTag("tag1"); - f1.addTag("tag2"); - assertFalse(f1.equals(f2)); - } - - @Test - public void testNotEquals_Attributes() { - Filter f1 = new Filter(); - Filter f2 = new Filter(); - f1.addAttribute("key", "value1"); - f1.addAttribute("key", "value1"); - assertFalse(f1.equals(f2)); - } - - @Test - public void testNotEquals_Null() { - Filter f1 = new Filter(); - assertFalse(f1.equals(null)); - } - - @Test - public void testAddKeys() { - Filter f1 = new Filter().addKey("key1").addKey("key2").addKey("key3"); - Filter f2 = new Filter().addKey("key1").addKeys("key2", "key3"); - assertEquals(f1, f2); - } - - @Test - public void testAddKeysSet() { - Filter f1 = new Filter().addKey("key1").addKey("key2").addKey("key3"); - HashSet keys = new HashSet(); - keys.add("key2"); - keys.add("key3"); - Filter f2 = new Filter().addKey("key1").addKeys(keys); - assertEquals(f1, f2); - } - - @Test - public void testAddTags() { - Filter f1 = new Filter().addTag("tag1").addTag("tag2").addTag("tag3"); - Filter f2 = new Filter().addTag("tag1").addTags("tag2", "tag3"); - assertEquals(f1, f2); - } - - @Test - public void testAddTagsSet() { - Filter f1 = new Filter().addTag("tag1").addTag("tag2").addTag("tag3"); - HashSet tags = new HashSet(); - tags.add("tag2"); - tags.add("tag3"); - Filter f2 = new Filter().addTag("tag1").addTags(tags); - assertEquals(f1, f2); - } - - @Test - public void testAddAttributes() { - Filter f1 = new Filter().addAttribute("key1", "value1").addAttribute("key2", "value2").addAttribute("key3", "value3"); - HashMap attributes = new HashMap(); - attributes.put("key2", "value2"); - attributes.put("key3", "value3"); - Filter f2 = new Filter().addAttribute("key1", "value1").addAttributes(attributes); - assertEquals(f1, f2); - } -} diff --git a/src/test/java/com/tempodb/FindDataPointsBySeriesTest.java b/src/test/java/com/tempodb/FindDataPointsBySeriesTest.java deleted file mode 100644 index 9621634..0000000 --- a/src/test/java/com/tempodb/FindDataPointsBySeriesTest.java +++ /dev/null @@ -1,232 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.message.BasicNameValuePair; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; -import org.junit.rules.ExpectedException; - - -public class FindDataPointsBySeriesTest { - private static final DateTimeZone zone = DateTimeZone.UTC; - private static final Series series = new Series("key1"); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private static final String json = "{" + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{" + - "\"interval\":{\"start\":\"2012-01-01T00:00:00.000+00:00\",\"end\":\"2012-01-02T00:00:00.000+00:00\"}," + - "\"found\":{\"t\":\"2012-01-01T00:00:01.000+00:00\",\"v\":12.34}" + - "}" + - "]," + - "\"predicate\":{" + - "\"function\":\"max\"," + - "\"period\":\"PT1M\"" + - "}" + - "}"; - - private static final String json1 = "{" + - "\"data\":[" + - "{" + - "\"interval\":{\"start\":\"2012-03-27T00:00:00.000+00:00\",\"end\":\"2012-03-27T00:01:00.000+00:00\"}," + - "\"found\":{\"t\":\"2012-03-27T00:00:00.000+00:00\",\"v\":12.34}" + - "}," + - "{" + - "\"interval\":{\"start\":\"2012-03-27T00:01:00.000+00:00\",\"end\":\"2012-03-27T00:02:00.000+00:00\"}," + - "\"found\":{\"t\":\"2012-03-27T00:01:00.000+00:00\",\"v\":23.45}" + - "}" + - "]," + - "\"tz\":\"UTC\"," + - "\"predicate\":{" + - "\"function\":\"max\"," + - "\"period\":\"PT1M\"" + - "}" + - "}"; - - private static final String json2 = "{" + - "\"data\":[" + - "{" + - "\"interval\":{\"start\":\"2012-03-27T00:02:00.000+00:00\",\"end\":\"2012-03-27T00:03:00.000+00:00\"}," + - "\"found\":{\"t\":\"2012-03-27T00:02:00.000+00:00\",\"v\":34.56}" + - "}" + - "]," + - "\"tz\":\"UTC\"," + - "\"predicate\":{" + - "\"function\":\"max\"," + - "\"period\":\"PT1M\"" + - "}" + - "}"; - - private static final String jsonTz = "{" + - "\"data\":[" + - "{" + - "\"interval\":{\"start\":\"2012-03-27T00:00:00.000+00:00\",\"end\":\"2012-03-27T00:01:00.000+00:00\"}," + - "\"found\":{\"t\":\"2012-03-27T00:00:00.000-05:00\",\"v\":12.34}" + - "}," + - "{" + - "\"interval\":{\"start\":\"2012-03-27T00:01:00.000+00:00\",\"end\":\"2012-03-27T00:02:00.000+00:00\"}," + - "\"found\":{\"t\":\"2012-03-27T00:01:00.000-05:00\",\"v\":23.45}" + - "}" + - "]," + - "\"tz\":\"America/Chicago\"," + - "\"predicate\":{" + - "\"function\":\"max\"," + - "\"period\":\"PT1M\"" + - "}" + - "}"; - - private static final DateTime start = new DateTime(2012, 3, 27, 0, 0, 0, 0, zone); - private static final DateTime end = new DateTime(2012, 3, 28, 0, 0, 0, 0, zone); - private static final Interval interval = new Interval(start, end); - private static final Predicate predicate = new Predicate(Period.minutes(1), "max"); - private static final DateTime dt0 = new DateTime(2012, 3, 27, 0, 0, 0, 0, zone); - private static final DateTime dt1 = new DateTime(2012, 3, 27, 0, 1, 0, 0, zone); - private static final DateTime dt2 = new DateTime(2012, 3, 27, 0, 2, 0, 0, zone); - private static final DateTime dt3 = new DateTime(2012, 3, 27, 0, 3, 0, 0, zone); - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, json1); - Client client = Util.getClient(response); - - Cursor cursor = client.findDataPoints(series, new Interval(start, end), predicate, zone); - - List expected = Arrays.asList( - new DataPointFound(new Interval(dt0, dt1), new DataPoint(dt0, 12.34)), - new DataPointFound(new Interval(dt1, dt2), new DataPoint(dt1, 23.45)) - ); - - List output = new ArrayList(); - for(DataPointFound dp : cursor) { - output.add(dp); - } - assertEquals(expected, output); - } - - @Test - public void smokeTestTz() throws IOException { - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - HttpResponse response = Util.getResponse(200, jsonTz); - Client client = Util.getClient(response); - - Cursor cursor = client.findDataPoints(series, new Interval(start, end), predicate, zone); - - List expected = Arrays.asList( - new DataPointFound(new Interval(new DateTime(2012, 3, 26, 19, 0, 0, 0, zone), new DateTime(2012, 3, 26, 19, 1, 0, 0, zone)), new DataPoint(new DateTime(2012, 3, 27, 0, 0, 0, 0, zone), 12.34)), - new DataPointFound(new Interval(new DateTime(2012, 3, 26, 19, 1, 0, 0, zone), new DateTime(2012, 3, 26, 19, 2, 0, 0, zone)), new DataPoint(new DateTime(2012, 3, 27, 0, 1, 0, 0, zone), 23.45)) - ); - - List output = new ArrayList(); - for(DataPointFound dp : cursor) { - output.add(dp); - } - assertEquals(expected, output); - } - - @Test - public void smokeTestMultipleClientCalls() throws IOException { - HttpResponse response1 = Util.getResponse(200, json1); - response1.addHeader("Link", "; rel=\"next\""); - HttpResponse response2 = Util.getResponse(200, json2); - HttpClient mockClient = Util.getMockHttpClient(response1, response2); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.findDataPoints(series, new Interval(start, end), predicate, zone); - - List expected = Arrays.asList( - new DataPointFound(new Interval(dt0, dt1), new DataPoint(dt0, 12.34)), - new DataPointFound(new Interval(dt1, dt2), new DataPoint(dt1, 23.45)), - new DataPointFound(new Interval(dt2, dt3), new DataPoint(dt2, 34.56)) - ); - - List output = new ArrayList(); - for(DataPointFound dp : cursor) { - output.add(dp); - } - assertEquals(expected, output); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.findDataPoints(series, interval, predicate, zone); - List output = new ArrayList(); - for(DataPointFound dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("GET", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.findDataPoints(series, interval, predicate, zone); - List output = new ArrayList(); - for(DataPointFound dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/series/key/key1/find/", uri.getPath()); - } - - @Test - public void testParametersPredicate() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.findDataPoints(series, interval, predicate, zone); - List output = new ArrayList(); - for(DataPointFound dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("start", "2012-03-27T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("end", "2012-03-28T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertTrue(params.contains(new BasicNameValuePair("predicate.period", "PT1M"))); - assertTrue(params.contains(new BasicNameValuePair("predicate.function", "max"))); - assertEquals(5, params.size()); - } - - @Test - public void testError() throws IOException { - HttpResponse response = Util.getResponse(403, "You are forbidden"); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - Cursor cursor = client.findDataPoints(series, interval, predicate, zone); - - thrown.expect(TempoDBException.class); - cursor.iterator().next(); - } -} diff --git a/src/test/java/com/tempodb/GetSeriesByFilterTest.java b/src/test/java/com/tempodb/GetSeriesByFilterTest.java deleted file mode 100644 index 0e4afb3..0000000 --- a/src/test/java/com/tempodb/GetSeriesByFilterTest.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.message.BasicNameValuePair; -import org.junit.*; -import static org.junit.Assert.*; -import org.junit.rules.ExpectedException; - - -public class GetSeriesByFilterTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private static final String json = "[" + - "{\"id\":\"id1\",\"key\":\"key1\",\"name\":\"name1\",\"tags\":[],\"attributes\":{}}" + - "]"; - - private static final String json1 = "[" + - "{\"id\":\"id1\",\"key\":\"key1\",\"name\":\"name1\",\"tags\":[],\"attributes\":{}}," + - "{\"id\":\"id2\",\"key\":\"key2\",\"name\":\"name2\",\"tags\":[],\"attributes\":{}}" + - "]"; - - private static final String json2 = "[" + - "{\"id\":\"id3\",\"key\":\"key3\",\"name\":\"name3\",\"tags\":[],\"attributes\":{}}" + - "]"; - - private static final Series series1 = new Series("key1", "name1", new HashSet(), new HashMap()); - private static final Series series2 = new Series("key2", "name2", new HashSet(), new HashMap()); - private static final Series series3 = new Series("key3", "name3", new HashSet(), new HashMap()); - private static final Filter filter = new Filter(); - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, json); - Client client = Util.getClient(response); - - List expected = Arrays.asList(series1); - - Cursor cursor = client.getSeries(filter); - List output = new ArrayList(); - for(Series series : cursor) { - output.add(series); - } - assertEquals(expected, output); - } - - @Test - public void smokeTestMultipleClientCalls() throws IOException { - HttpResponse response1 = Util.getResponse(200, json1); - response1.addHeader("Link", "; rel=\"next\""); - HttpResponse response2 = Util.getResponse(200, json2); - HttpClient mockClient = Util.getMockHttpClient(response1, response2); - Client client = Util.getClient(mockClient); - - List expected = Arrays.asList(series1, series2, series3); - - Cursor cursor = client.getSeries(filter); - List output = new ArrayList(); - for(Series series : cursor) { - output.add(series); - } - assertEquals(expected, output); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.getSeries(filter); - List output = new ArrayList(); - for(Series series : cursor) { - output.add(series); - } - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("GET", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.getSeries(filter); - List output = new ArrayList(); - for(Series series : cursor) { - output.add(series); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/series/", uri.getPath()); - } - - @Test - public void testParameters() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter(); - filter.addKey("key1"); - filter.addTag("tag1"); - filter.addTag("tag1"); - filter.addAttribute("key1", "value1"); - filter.addAttribute("key2", "value2"); - - Cursor cursor = client.getSeries(filter); - List output = new ArrayList(); - for(Series series : cursor) { - output.add(series); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("key", "key1"))); - assertTrue(params.contains(new BasicNameValuePair("tag", "tag1"))); - assertTrue(params.contains(new BasicNameValuePair("attr[key1]", "value1"))); - assertTrue(params.contains(new BasicNameValuePair("attr[key2]", "value2"))); - assertEquals(4, params.size()); - } - - @Test - public void testError() throws IOException { - HttpResponse response = Util.getResponse(403, "You are forbidden"); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.getSeries(filter); - - thrown.expect(TempoDBException.class); - cursor.iterator().next(); - } -} diff --git a/src/test/java/com/tempodb/GetSeriesByKeyTest.java b/src/test/java/com/tempodb/GetSeriesByKeyTest.java deleted file mode 100644 index d6cc9ce..0000000 --- a/src/test/java/com/tempodb/GetSeriesByKeyTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.junit.*; -import static org.junit.Assert.*; - - -public class GetSeriesByKeyTest { - - private static final String json = "{\"id\":\"id1\",\"key\":\"key1\",\"name\":\"name1\",\"tags\":[],\"attributes\":{}}"; - private static final String json2 = "{\"id\":\"id1\",\"key\":\"appidÜ:1234.txn:/def ault.cou+()+={}nt\",\"name\":\"name1\",\"tags\":[],\"attributes\":{\"appidÜ\":\"1234\",\"txn\":\"def ault\"}}"; - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, json); - Client client = Util.getClient(response); - - Result expected = new Result(new Series("key1", "name1", new HashSet(), new HashMap()), 200, "OK"); - Result result = client.getSeries("key1"); - assertEquals(expected, result); - } - - @Test - public void smokeTestUnescapedKey() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json2); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Map attributes = new HashMap(); - attributes.put("appidÜ", "1234"); - attributes.put("txn", "def ault"); - Result expected = new Result(new Series("appidÜ:1234.txn:/def ault.cou+()+={}nt", "name1", new HashSet(), attributes), 200, "OK"); - - Result result = client.getSeries("appidÜ:1234.txn:/def ault.cou+()+={}nt"); - assertEquals(expected, result); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/series/key/appid%C3%9C%3A1234.txn%3A%2Fdef%20ault.cou%2B%28%29%2B%3D%7B%7Dnt/", uri.getRawPath()); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.getSeries("key1"); - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("GET", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.getSeries("key1"); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/series/key/key1/", uri.getPath()); - } -} diff --git a/src/test/java/com/tempodb/InterpolationTest.java b/src/test/java/com/tempodb/InterpolationTest.java deleted file mode 100644 index 7eac1a6..0000000 --- a/src/test/java/com/tempodb/InterpolationTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.tempodb; - -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; - - -public class InterpolationTest { - - @Test - public void testEquals() { - Interpolation r1 = new Interpolation(Period.minutes(1), InterpolationFunction.LINEAR); - Interpolation r2 = new Interpolation(Period.minutes(1), InterpolationFunction.LINEAR); - assertEquals(r1, r2); - } - - @Test - public void testNotEquals_Period() { - Interpolation r1 = new Interpolation(Period.minutes(1), InterpolationFunction.LINEAR); - Interpolation r2 = new Interpolation(Period.minutes(2), InterpolationFunction.LINEAR); - assertFalse(r1.equals(r2)); - } - - @Test - public void testNotEquals_InterpolationFunction() { - Interpolation r1 = new Interpolation(Period.minutes(1), InterpolationFunction.LINEAR); - Interpolation r2 = new Interpolation(Period.minutes(1), InterpolationFunction.ZOH); - assertFalse(r1.equals(r2)); - } - - @Test - public void testNotEquals_Null() { - Interpolation r1 = new Interpolation(Period.minutes(1), InterpolationFunction.LINEAR); - assertFalse(r1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/MultiDataPointTest.java b/src/test/java/com/tempodb/MultiDataPointTest.java deleted file mode 100644 index 2d381c3..0000000 --- a/src/test/java/com/tempodb/MultiDataPointTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.tempodb; - -import java.util.HashMap; -import java.util.Map; - -import org.joda.time.DateTime; -import org.junit.*; -import static org.junit.Assert.*; - - -public class MultiDataPointTest { - - private static final Map data1; - private static final Map data2; - private static final Map data3; - - static { - data1 = new HashMap(); - data1.put("key1", 12.34); - data1.put("key2", 23.45); - - data2 = new HashMap(); - data2.put("key1", 12.34); - data2.put("key2", 23.45); - - data3 = new HashMap(); - data3.put("key1", 12.34); - } - - @Test - public void testEquals() { - MultiDataPoint mdp1 = new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), data1); - MultiDataPoint mdp2 = new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), data2); - assertEquals(mdp1, mdp2); - } - - @Test - public void testNotEquals_DateTime() { - MultiDataPoint mdp1 = new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), data1); - MultiDataPoint mdp2 = new MultiDataPoint(new DateTime(2012, 1, 2, 0, 0, 0, 0), data2); - assertFalse(mdp1.equals(mdp2)); - } - - @Test - public void testNotEquals_Data() { - MultiDataPoint mdp1 = new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), data1); - MultiDataPoint mdp2 = new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), data3); - assertFalse(mdp1.equals(mdp2)); - } - - @Test - public void testNotEquals_Null() { - MultiDataPoint mdp1 = new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), data1); - assertFalse(mdp1.equals(null)); - } - - @Test - public void testGetMissingIsNull() { - MultiDataPoint mdp1 = new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), data1); - assertEquals(mdp1.get("blah"), null); - } -} diff --git a/src/test/java/com/tempodb/MultiRollupTest.java b/src/test/java/com/tempodb/MultiRollupTest.java deleted file mode 100644 index 23ae8c9..0000000 --- a/src/test/java/com/tempodb/MultiRollupTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.tempodb; - -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; - - -public class MultiRollupTest { - - private static Period p1 = Period.minutes(1); - private static Period p2 = Period.minutes(1); - private static Period p3 = Period.minutes(2); - - private static Fold[] f1 = new Fold[] { Fold.MEAN, Fold.SUM }; - private static Fold[] f2 = new Fold[] { Fold.MEAN, Fold.SUM }; - private static Fold[] f3 = new Fold[] { Fold.SUM }; - - @Test - public void testEquals() { - MultiRollup mr1 = new MultiRollup(p1, f1); - MultiRollup mr2 = new MultiRollup(p2, f2); - assertEquals(mr1, mr2); - } - - @Test - public void testNotEquals_Period() { - MultiRollup mr1 = new MultiRollup(p1, f1); - MultiRollup mr2 = new MultiRollup(p3, f2); - assertFalse(mr1.equals(mr2)); - } - - @Test - public void testNotEquals_Fold() { - MultiRollup mr1 = new MultiRollup(p1, f1); - MultiRollup mr2 = new MultiRollup(p2, f3); - assertFalse(mr1.equals(mr2)); - } - - @Test - public void testNotEquals_Null() { - MultiRollup mr1 = new MultiRollup(p1, f1); - assertFalse(mr1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/MultiStatusTest.java b/src/test/java/com/tempodb/MultiStatusTest.java deleted file mode 100644 index 2d8ff3c..0000000 --- a/src/test/java/com/tempodb/MultiStatusTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.tempodb; - -import java.util.Arrays; -import java.util.List; - -import org.junit.*; -import static org.junit.Assert.*; - - -public class MultiStatusTest { - - private static final List statuses1 = Arrays.asList(new Status(1, Arrays.asList("message"))); - private static final List statuses2 = Arrays.asList(new Status(1, Arrays.asList("message"))); - private static final List statuses3 = Arrays.asList(new Status(100, Arrays.asList("message1"))); - - @Test - public void testEquals() { - MultiStatus m1 = new MultiStatus(statuses1); - MultiStatus m2 = new MultiStatus(statuses2); - assertEquals(m1, m2); - } - - @Test - public void testNotEquals() { - MultiStatus m1 = new MultiStatus(statuses1); - MultiStatus m2 = new MultiStatus(statuses3); - assertFalse(m1.equals(m2)); - } - - @Test - public void testNotEquals_Null() { - MultiStatus m1 = new MultiStatus(statuses1); - assertFalse(m1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/PredicateTest.java b/src/test/java/com/tempodb/PredicateTest.java deleted file mode 100644 index db4928e..0000000 --- a/src/test/java/com/tempodb/PredicateTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.tempodb; - -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; - - -public class PredicateTest { - - @Test - public void testEquals() { - Predicate r1 = new Predicate(Period.minutes(1), "max"); - Predicate r2 = new Predicate(Period.minutes(1), "max"); - assertEquals(r1, r2); - } - - @Test - public void testNotEquals_Period() { - Predicate r1 = new Predicate(Period.minutes(1), "max"); - Predicate r2 = new Predicate(Period.minutes(2), "max"); - assertFalse(r1.equals(r2)); - } - - @Test - public void testNotEquals_Fold() { - Predicate r1 = new Predicate(Period.minutes(1), "max"); - Predicate r2 = new Predicate(Period.minutes(1), "min"); - assertFalse(r1.equals(r2)); - } - - @Test - public void testNotEquals_Null() { - Predicate r1 = new Predicate(Period.minutes(1), "max"); - assertFalse(r1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/ReadDataPointsByFilterTest.java b/src/test/java/com/tempodb/ReadDataPointsByFilterTest.java deleted file mode 100644 index ae5f992..0000000 --- a/src/test/java/com/tempodb/ReadDataPointsByFilterTest.java +++ /dev/null @@ -1,307 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.message.BasicNameValuePair; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; -import org.junit.rules.ExpectedException; - - -public class ReadDataPointsByFilterTest { - private static final DateTimeZone zone = DateTimeZone.UTC; - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private static final String json = "{" + - "\"rollup\":{" + - "\"fold\":\"sum\"," + - "\"period\":\"PT1H\"" + - "}," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:00.000Z\",\"v\":12.34}" + - "]" + - "}"; - - private static final String json1 = "{" + - "\"rollup\":null," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-03-27T05:00:00.000Z\",\"v\":12.34}," + - "{\"t\":\"2012-03-27T05:01:00.000Z\",\"v\":23.45}" + - "]" + - "}"; - - private static final String json2 = "{" + - "\"rollup\":null," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-03-27T05:02:00.000Z\",\"v\":34.56}" + - "]" + - "}"; - - private static final String jsonTz = "{" + - "\"rollup\":null," + - "\"tz\":\"America/Chicago\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:00.000-06:00\",\"v\":34.56}" + - "]" + - "}"; - - private static final DateTime start = new DateTime(2012, 1, 1, 0, 0, 0, 0, zone); - private static final DateTime end = new DateTime(2012, 1, 2, 0, 0, 0, 0, zone); - private static final Interval interval = new Interval(start, end); - private static final Rollup rollup = new Rollup(Period.minutes(1), Fold.SUM); - private static final Aggregation aggregation = new Aggregation(Fold.SUM); - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, json1); - Client client = Util.getClient(response); - DateTime start = new DateTime(2012, 3, 27, 0, 0, 0, zone); - DateTime end = new DateTime(2012, 3, 28, 0, 0, 0, zone); - Filter filter = new Filter(); - filter.addKey("key1"); - - List expected = Arrays.asList(new DataPoint(new DateTime(2012, 3, 27, 5, 0, 0, 0, zone), 12.34), - new DataPoint(new DateTime(2012, 3, 27, 5, 1, 0, 0, zone), 23.45)); - - Cursor cursor = client.readDataPoints(filter, new Interval(start, end), zone, aggregation); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - assertEquals(expected, output); - } - - @Test - public void smokeTestTz() throws IOException { - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - HttpResponse response = Util.getResponse(200, jsonTz); - Client client = Util.getClient(response); - DateTime start = new DateTime(2012, 1, 1, 0, 0, 0, zone); - DateTime end = new DateTime(2012, 1, 1, 0, 0, 0, zone); - Filter filter = new Filter(); - filter.addKey("key1"); - - List expected = Arrays.asList(new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, zone), 34.56)); - - Cursor cursor = client.readDataPoints(filter, new Interval(start, end), zone, aggregation); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - assertEquals(expected, output); - } - - @Test - public void smokeTestMultipleClientCalls() throws IOException { - HttpResponse response1 = Util.getResponse(200, json1); - response1.addHeader("Link", "; rel=\"next\""); - HttpResponse response2 = Util.getResponse(200, json2); - HttpClient mockClient = Util.getMockHttpClient(response1, response2); - Client client = Util.getClient(mockClient); - DateTime start = new DateTime(2012, 3, 27, 0, 0, 0, 0, zone); - DateTime end = new DateTime(2012, 3, 28, 0, 0, 0, 0, zone); - Filter filter = new Filter(); - filter.addKey("key1"); - - List expected = Arrays.asList(new DataPoint(new DateTime(2012, 3, 27, 5, 0, 0, 0, zone), 12.34), - new DataPoint(new DateTime(2012, 3, 27, 5, 1, 0, 0, zone), 23.45), - new DataPoint(new DateTime(2012, 3, 27, 5, 2, 0, 0, zone), 34.56)); - - Cursor cursor = client.readDataPoints(filter, new Interval(start, end), zone, aggregation); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - assertEquals(expected, output); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter(); - filter.addKey("key1"); - - Cursor cursor = client.readDataPoints(filter, interval, zone, aggregation); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("GET", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter(); - filter.addKey("key1"); - - Cursor cursor = client.readDataPoints(filter, interval, zone, aggregation); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/segment/", uri.getPath()); - } - - @Test - public void testParametersNoRollup() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter(); - filter.addKey("key1"); - - Cursor cursor = client.readDataPoints(filter, interval, zone, aggregation); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("key", "key1"))); - assertTrue(params.contains(new BasicNameValuePair("start", "2012-01-01T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("end", "2012-01-02T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("aggregation.fold", "sum"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertEquals(5, params.size()); - } - - @Test - public void testParametersRollup() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter(); - filter.addKey("key1"); - - Cursor cursor = client.readDataPoints(filter, interval, zone, aggregation, rollup, null); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("key", "key1"))); - assertTrue(params.contains(new BasicNameValuePair("start", "2012-01-01T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("end", "2012-01-02T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertTrue(params.contains(new BasicNameValuePair("rollup.period", "PT1M"))); - assertTrue(params.contains(new BasicNameValuePair("rollup.fold", "sum"))); - assertTrue(params.contains(new BasicNameValuePair("aggregation.fold", "sum"))); - assertEquals(7, params.size()); - } - - @Test - public void testParametersRollupInterpolation() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter().addKey("key1"); - Interpolation interpolation = Interpolation.linear(Period.minutes(1)); - - Cursor cursor = client.readDataPoints(filter, interval, zone, aggregation, rollup, interpolation); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("key", "key1"))); - assertTrue(params.contains(new BasicNameValuePair("start", "2012-01-01T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("end", "2012-01-02T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertTrue(params.contains(new BasicNameValuePair("rollup.period", "PT1M"))); - assertTrue(params.contains(new BasicNameValuePair("rollup.fold", "sum"))); - assertTrue(params.contains(new BasicNameValuePair("interpolation.period", "PT1M"))); - assertTrue(params.contains(new BasicNameValuePair("interpolation.function", "linear"))); - assertTrue(params.contains(new BasicNameValuePair("aggregation.fold", "sum"))); - assertEquals(9, params.size()); - } - - @Test - public void testParametersFullFilter() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter(); - filter.addKey("key1"); - filter.addTag("tag1"); - filter.addTag("tag1"); - filter.addAttribute("key1", "value1"); - filter.addAttribute("key2", "value2"); - - Cursor cursor = client.readDataPoints(filter, interval, zone, aggregation); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("key", "key1"))); - assertTrue(params.contains(new BasicNameValuePair("tag", "tag1"))); - assertTrue(params.contains(new BasicNameValuePair("attr[key1]", "value1"))); - assertTrue(params.contains(new BasicNameValuePair("attr[key2]", "value2"))); - assertTrue(params.contains(new BasicNameValuePair("start", "2012-01-01T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("end", "2012-01-02T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("aggregation.fold", "sum"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertEquals(8, params.size()); - } - - @Test - public void testError() throws IOException { - HttpResponse response = Util.getResponse(403, "You are forbidden"); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter(); - filter.addKey("key1"); - - Cursor cursor = client.readDataPoints(filter, interval, zone, aggregation); - - thrown.expect(TempoDBException.class); - cursor.iterator().next(); - } -} diff --git a/src/test/java/com/tempodb/ReadDataPointsBySeriesTest.java b/src/test/java/com/tempodb/ReadDataPointsBySeriesTest.java deleted file mode 100644 index 288f032..0000000 --- a/src/test/java/com/tempodb/ReadDataPointsBySeriesTest.java +++ /dev/null @@ -1,256 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.message.BasicNameValuePair; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; -import org.junit.rules.ExpectedException; - - -public class ReadDataPointsBySeriesTest { - private static final DateTimeZone zone = DateTimeZone.UTC; - private static final Series series = new Series("key1"); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private static final String json = "{" + - "\"rollup\":{" + - "\"fold\":\"sum\"," + - "\"period\":\"PT1H\"" + - "}," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:00.000Z\",\"v\":12.34}" + - "]" + - "}"; - - private static final String json1 = "{" + - "\"rollup\":null," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-03-27T05:00:00.000Z\",\"v\":12.34}," + - "{\"t\":\"2012-03-27T05:01:00.000Z\",\"v\":23.45}" + - "]" + - "}"; - - private static final String json2 = "{" + - "\"rollup\":null," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-03-27T05:02:00.000Z\",\"v\":34.56}" + - "]" + - "}"; - - private static final String jsonTz = "{" + - "\"rollup\":null," + - "\"tz\":\"America/Chicago\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:00.000-06:00\",\"v\":34.56}" + - "]" + - "}"; - - private static final DateTime start = new DateTime(2012, 1, 1, 0, 0, 0, 0, zone); - private static final DateTime end = new DateTime(2012, 1, 2, 0, 0, 0, 0, zone); - private static final Interval interval = new Interval(start, end); - private static final Rollup rollup = new Rollup(Period.minutes(1), Fold.SUM); - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, json1); - Client client = Util.getClient(response); - DateTime start = new DateTime(2012, 3, 27, 0, 0, 0, zone); - DateTime end = new DateTime(2012, 3, 28, 0, 0, 0, zone); - - List expected = Arrays.asList(new DataPoint(new DateTime(2012, 3, 27, 5, 0, 0, 0, zone), 12.34), - new DataPoint(new DateTime(2012, 3, 27, 5, 1, 0, 0, zone), 23.45)); - - Cursor cursor = client.readDataPoints(series, new Interval(start, end), zone); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - assertEquals(expected, output); - } - - @Test - public void smokeTestNext() throws IOException { - HttpResponse response = Util.getResponse(200, json1); - Client client = Util.getClient(response); - DateTime start = new DateTime(2012, 3, 27, 0, 0, 0, zone); - DateTime end = new DateTime(2012, 3, 28, 0, 0, 0, zone); - - DataPoint expected = new DataPoint(new DateTime(2012, 3, 27, 5, 0, 0, 0, zone), 12.34); - - Cursor cursor = client.readDataPoints(series, new Interval(start, end), zone); - assertEquals(expected, cursor.iterator().next()); - } - - @Test - public void smokeTestTz() throws IOException { - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - HttpResponse response = Util.getResponse(200, jsonTz); - Client client = Util.getClient(response); - DateTime start = new DateTime(2012, 1, 1, 0, 0, 0, zone); - DateTime end = new DateTime(2012, 1, 1, 0, 0, 0, zone); - - List expected = Arrays.asList(new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, zone), 34.56)); - - Cursor cursor = client.readDataPoints(series, new Interval(start, end), zone); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - assertEquals(expected, output); - } - - @Test - public void smokeTestMultipleClientCalls() throws IOException { - HttpResponse response1 = Util.getResponse(200, json1); - response1.addHeader("Link", "; rel=\"next\""); - HttpResponse response2 = Util.getResponse(200, json2); - HttpClient mockClient = Util.getMockHttpClient(response1, response2); - Client client = Util.getClient(mockClient); - DateTime start = new DateTime(2012, 3, 27, 0, 0, 0, 0, zone); - DateTime end = new DateTime(2012, 3, 28, 0, 0, 0, 0, zone); - - List expected = Arrays.asList(new DataPoint(new DateTime(2012, 3, 27, 5, 0, 0, 0, zone), 12.34), - new DataPoint(new DateTime(2012, 3, 27, 5, 1, 0, 0, zone), 23.45), - new DataPoint(new DateTime(2012, 3, 27, 5, 2, 0, 0, zone), 34.56)); - - Cursor cursor = client.readDataPoints(series, new Interval(start, end), zone); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - assertEquals(expected, output); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.readDataPoints(series, interval, zone); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("GET", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.readDataPoints(series, interval, zone); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/series/key/key1/segment/", uri.getPath()); - } - - @Test - public void testParametersNoRollup() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.readDataPoints(series, interval, zone); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("start", "2012-01-01T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("end", "2012-01-02T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertEquals(3, params.size()); - } - - @Test - public void testParametersRollup() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.readDataPoints(series, interval, zone, rollup, null); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("start", "2012-01-01T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("end", "2012-01-02T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertTrue(params.contains(new BasicNameValuePair("rollup.period", "PT1M"))); - assertTrue(params.contains(new BasicNameValuePair("rollup.fold", "sum"))); - assertEquals(5, params.size()); - } - - @Test - public void testParametersRollupInterpolation() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Interpolation interpolation = Interpolation.zoh(Period.minutes(1)); - Cursor cursor = client.readDataPoints(series, interval, zone, rollup, interpolation); - List output = new ArrayList(); - for(DataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("start", "2012-01-01T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("end", "2012-01-02T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertTrue(params.contains(new BasicNameValuePair("rollup.period", "PT1M"))); - assertTrue(params.contains(new BasicNameValuePair("rollup.fold", "sum"))); - assertTrue(params.contains(new BasicNameValuePair("interpolation.period", "PT1M"))); - assertTrue(params.contains(new BasicNameValuePair("interpolation.function", "zoh"))); - assertEquals(7, params.size()); - } - - @Test - public void testError() throws IOException { - HttpResponse response = Util.getResponse(403, "You are forbidden"); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - Cursor cursor = client.readDataPoints(series, interval, zone, rollup, null); - - thrown.expect(TempoDBException.class); - cursor.iterator().next(); - } -} diff --git a/src/test/java/com/tempodb/ReadMultiDataPointsTest.java b/src/test/java/com/tempodb/ReadMultiDataPointsTest.java deleted file mode 100644 index b5cf40d..0000000 --- a/src/test/java/com/tempodb/ReadMultiDataPointsTest.java +++ /dev/null @@ -1,328 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.message.BasicNameValuePair; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; -import org.junit.rules.ExpectedException; - - -public class ReadMultiDataPointsTest { - private static final DateTimeZone zone = DateTimeZone.UTC; - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private static final String json = "{" + - "\"rollup\":{" + - "\"fold\":\"sum\"," + - "\"period\":\"PT1H\"" + - "}," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:00.000Z\",\"v\":{\"key1\":12.34,\"key2\":23.45}}" + - "]" + - "}"; - - private static final String json1 = "{" + - "\"rollup\":null," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-03-27T05:00:00.000Z\",\"v\":{\"key1\":12.34,\"key2\":23.45}}," + - "{\"t\":\"2012-03-27T05:01:00.000Z\",\"v\":{\"key1\":23.45,\"key2\":34.56}}" + - "]" + - "}"; - - private static final String json2 = "{" + - "\"rollup\":null," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-03-27T05:02:00.000Z\",\"v\":{\"key1\":34.56,\"key2\":45.67}}" + - "]" + - "}"; - - private static final String jsonTz = "{" + - "\"rollup\":null," + - "\"tz\":\"America/Chicago\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:00.000-06:00\",\"v\":{\"key1\":34.56,\"key2\":45.67}}" + - "]" + - "}"; - - private static final DateTime start = new DateTime(2012, 1, 1, 0, 0, 0, 0, zone); - private static final DateTime end = new DateTime(2012, 1, 2, 0, 0, 0, 0, zone); - private static final Interval interval = new Interval(start, end); - private static final Rollup rollup = new Rollup(Period.minutes(1), Fold.SUM); - - private static final Map data1; - private static final Map data2; - private static final Map data3; - - static { - data1 = new HashMap(); - data1.put("key1", 12.34); - data1.put("key2", 23.45); - - data2 = new HashMap(); - data2.put("key1", 23.45); - data2.put("key2", 34.56); - - data3 = new HashMap(); - data3.put("key1", 34.56); - data3.put("key2", 45.67); - } - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, json1); - Client client = Util.getClient(response); - DateTime start = new DateTime(2012, 3, 27, 0, 0, 0, zone); - DateTime end = new DateTime(2012, 3, 28, 0, 0, 0, zone); - Filter filter = new Filter(); - filter.addKey("key1"); - - List expected = Arrays.asList( - new MultiDataPoint(new DateTime(2012, 3, 27, 5, 0, 0, 0, zone), data1), - new MultiDataPoint(new DateTime(2012, 3, 27, 5, 1, 0, 0, zone), data2) - ); - - Cursor cursor = client.readMultiDataPoints(filter, new Interval(start, end), zone, null, null); - List output = new ArrayList(); - for(MultiDataPoint dp : cursor) { - output.add(dp); - } - assertEquals(expected, output); - } - - @Test - public void smokeTestTz() throws IOException { - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - HttpResponse response = Util.getResponse(200, jsonTz); - Client client = Util.getClient(response); - DateTime start = new DateTime(2012, 1, 1, 0, 0, 0, zone); - DateTime end = new DateTime(2012, 1, 1, 0, 0, 0, zone); - Filter filter = new Filter(); - filter.addKey("key1"); - - List expected = Arrays.asList( - new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, zone), data3) - ); - - Cursor cursor = client.readMultiDataPoints(filter, new Interval(start, end), zone, null, null); - List output = new ArrayList(); - for(MultiDataPoint dp : cursor) { - output.add(dp); - } - assertEquals(expected, output); - } - - @Test - public void smokeTestMultipleClientCalls() throws IOException { - HttpResponse response1 = Util.getResponse(200, json1); - response1.addHeader("Link", "; rel=\"next\""); - HttpResponse response2 = Util.getResponse(200, json2); - HttpClient mockClient = Util.getMockHttpClient(response1, response2); - Client client = Util.getClient(mockClient); - DateTime start = new DateTime(2012, 3, 27, 0, 0, 0, 0, zone); - DateTime end = new DateTime(2012, 3, 28, 0, 0, 0, 0, zone); - Filter filter = new Filter(); - filter.addKey("key1"); - - List expected = Arrays.asList( - new MultiDataPoint(new DateTime(2012, 3, 27, 5, 0, 0, 0, zone), data1), - new MultiDataPoint(new DateTime(2012, 3, 27, 5, 1, 0, 0, zone), data2), - new MultiDataPoint(new DateTime(2012, 3, 27, 5, 2, 0, 0, zone), data3) - ); - - Cursor cursor = client.readMultiDataPoints(filter, new Interval(start, end), zone, null, null); - List output = new ArrayList(); - for(MultiDataPoint dp : cursor) { - output.add(dp); - } - assertEquals(expected, output); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter(); - filter.addKey("key1"); - - Cursor cursor = client.readMultiDataPoints(filter, interval, zone, null, null); - List output = new ArrayList(); - for(MultiDataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("GET", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter(); - filter.addKey("key1"); - - Cursor cursor = client.readMultiDataPoints(filter, interval, zone, null, null); - List output = new ArrayList(); - for(MultiDataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/multi/", uri.getPath()); - } - - @Test - public void testParametersNoRollup() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter(); - filter.addKey("key1"); - - Cursor cursor = client.readMultiDataPoints(filter, interval, zone, null, null); - List output = new ArrayList(); - for(MultiDataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("key", "key1"))); - assertTrue(params.contains(new BasicNameValuePair("start", "2012-01-01T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("end", "2012-01-02T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertEquals(4, params.size()); - } - - @Test - public void testParametersRollup() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter(); - filter.addKey("key1"); - - Cursor cursor = client.readMultiDataPoints(filter, interval, zone, rollup, null); - List output = new ArrayList(); - for(MultiDataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("key", "key1"))); - assertTrue(params.contains(new BasicNameValuePair("start", "2012-01-01T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("end", "2012-01-02T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertTrue(params.contains(new BasicNameValuePair("rollup.period", "PT1M"))); - assertTrue(params.contains(new BasicNameValuePair("rollup.fold", "sum"))); - assertEquals(6, params.size()); - } - - @Test - public void testParametersRollupInterpolation() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter().addKey("key1"); - Interpolation interpolation = Interpolation.linear(Period.minutes(1)); - - Cursor cursor = client.readMultiDataPoints(filter, interval, zone, rollup, interpolation); - List output = new ArrayList(); - for(MultiDataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("key", "key1"))); - assertTrue(params.contains(new BasicNameValuePair("start", "2012-01-01T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("end", "2012-01-02T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertTrue(params.contains(new BasicNameValuePair("rollup.period", "PT1M"))); - assertTrue(params.contains(new BasicNameValuePair("rollup.fold", "sum"))); - assertTrue(params.contains(new BasicNameValuePair("interpolation.period", "PT1M"))); - assertTrue(params.contains(new BasicNameValuePair("interpolation.function", "linear"))); - assertEquals(8, params.size()); - } - - @Test - public void testParametersFullFilter() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter(); - filter.addKey("key1"); - filter.addTag("tag1"); - filter.addTag("tag1"); - filter.addAttribute("key1", "value1"); - filter.addAttribute("key2", "value2"); - - Cursor cursor = client.readMultiDataPoints(filter, interval, zone, null, null); - List output = new ArrayList(); - for(MultiDataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("key", "key1"))); - assertTrue(params.contains(new BasicNameValuePair("tag", "tag1"))); - assertTrue(params.contains(new BasicNameValuePair("attr[key1]", "value1"))); - assertTrue(params.contains(new BasicNameValuePair("attr[key2]", "value2"))); - assertTrue(params.contains(new BasicNameValuePair("start", "2012-01-01T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("end", "2012-01-02T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertEquals(7, params.size()); - } - - @Test - public void testError() throws IOException { - HttpResponse response = Util.getResponse(403, "You are forbidden"); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter(); - filter.addKey("key1"); - - Cursor cursor = client.readMultiDataPoints(filter, interval, zone); - - thrown.expect(TempoDBException.class); - cursor.iterator().next(); - } -} diff --git a/src/test/java/com/tempodb/ReadMultiRollupDataPointsTest.java b/src/test/java/com/tempodb/ReadMultiRollupDataPointsTest.java deleted file mode 100644 index 7958d60..0000000 --- a/src/test/java/com/tempodb/ReadMultiRollupDataPointsTest.java +++ /dev/null @@ -1,242 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.message.BasicNameValuePair; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; -import org.junit.rules.ExpectedException; - - -public class ReadMultiRollupDataPointsTest { - private static final DateTimeZone zone = DateTimeZone.UTC; - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private static final String json = "{" + - "\"series\":{\"id\":\"id1\",\"key\":\"key\",\"name\":\"\",\"tags\":[],\"attributes\":{}}," + - "\"rollup\":{" + - "\"folds\":[\"sum\",\"max\"]," + - "\"period\":\"PT1H\"" + - "}," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:00.000Z\",\"v\":{\"sum\":12.34,\"max\":23.45}}" + - "]" + - "}"; - - private static final String json1 = "{" + - "\"series\":{\"id\":\"id1\",\"key\":\"key\",\"name\":\"\",\"tags\":[],\"attributes\":{}}," + - "\"rollup\":{" + - "\"folds\":[\"sum\",\"max\"]," + - "\"period\":\"PT1H\"" + - "}," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-03-27T05:00:00.000Z\",\"v\":{\"sum\":12.34,\"max\":23.45}}," + - "{\"t\":\"2012-03-27T05:01:00.000Z\",\"v\":{\"sum\":23.45,\"max\":34.56}}" + - "]" + - "}"; - - private static final String json2 = "{" + - "\"series\":{\"id\":\"id1\",\"key\":\"key\",\"name\":\"\",\"tags\":[],\"attributes\":{}}," + - "\"rollup\":{" + - "\"folds\":[\"sum\",\"max\"]," + - "\"period\":\"PT1H\"" + - "}," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-03-27T05:02:00.000Z\",\"v\":{\"sum\":34.56,\"max\":45.67}}" + - "]" + - "}"; - - private static final String jsonTz = "{" + - "\"series\":{\"id\":\"id1\",\"key\":\"key\",\"name\":\"\",\"tags\":[],\"attributes\":{}}," + - "\"rollup\":{" + - "\"folds\":[\"sum\",\"max\"]," + - "\"period\":\"PT1H\"" + - "}," + - "\"tz\":\"America/Chicago\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:00.000-06:00\",\"v\":{\"sum\":34.56,\"max\":45.67}}" + - "]" + - "}"; - - private static final DateTime start = new DateTime(2012, 1, 1, 0, 0, 0, 0, zone); - private static final DateTime end = new DateTime(2012, 1, 2, 0, 0, 0, 0, zone); - private static final Interval interval = new Interval(start, end); - private static final MultiRollup rollup = new MultiRollup(Period.minutes(1), new Fold[] { Fold.SUM, Fold.MAX }); - private static final Series series = new Series("key"); - - private static final Map data1; - private static final Map data2; - private static final Map data3; - - static { - data1 = new HashMap(); - data1.put("sum", 12.34); - data1.put("max", 23.45); - - data2 = new HashMap(); - data2.put("sum", 23.45); - data2.put("max", 34.56); - - data3 = new HashMap(); - data3.put("sum", 34.56); - data3.put("max", 45.67); - } - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, json1); - Client client = Util.getClient(response); - DateTime start = new DateTime(2012, 3, 27, 0, 0, 0, zone); - DateTime end = new DateTime(2012, 3, 28, 0, 0, 0, zone); - - List expected = Arrays.asList( - new MultiDataPoint(new DateTime(2012, 3, 27, 5, 0, 0, 0, zone), data1), - new MultiDataPoint(new DateTime(2012, 3, 27, 5, 1, 0, 0, zone), data2) - ); - - Cursor cursor = client.readMultiRollupDataPoints(series, new Interval(start, end), zone, rollup, null); - List output = new ArrayList(); - for(MultiDataPoint dp : cursor) { - output.add(dp); - } - assertEquals(expected, output); - } - - @Test - public void smokeTestTz() throws IOException { - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - HttpResponse response = Util.getResponse(200, jsonTz); - Client client = Util.getClient(response); - DateTime start = new DateTime(2012, 1, 1, 0, 0, 0, zone); - DateTime end = new DateTime(2012, 1, 1, 0, 0, 0, zone); - - List expected = Arrays.asList( - new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, zone), data3) - ); - - Cursor cursor = client.readMultiRollupDataPoints(series, new Interval(start, end), zone, rollup, null); - List output = new ArrayList(); - for(MultiDataPoint dp : cursor) { - output.add(dp); - } - assertEquals(expected, output); - } - - @Test - public void smokeTestMultipleClientCalls() throws IOException { - HttpResponse response1 = Util.getResponse(200, json1); - response1.addHeader("Link", "; rel=\"next\""); - HttpResponse response2 = Util.getResponse(200, json2); - HttpClient mockClient = Util.getMockHttpClient(response1, response2); - Client client = Util.getClient(mockClient); - DateTime start = new DateTime(2012, 3, 27, 0, 0, 0, 0, zone); - DateTime end = new DateTime(2012, 3, 28, 0, 0, 0, 0, zone); - - List expected = Arrays.asList( - new MultiDataPoint(new DateTime(2012, 3, 27, 5, 0, 0, 0, zone), data1), - new MultiDataPoint(new DateTime(2012, 3, 27, 5, 1, 0, 0, zone), data2), - new MultiDataPoint(new DateTime(2012, 3, 27, 5, 2, 0, 0, zone), data3) - ); - - Cursor cursor = client.readMultiRollupDataPoints(series, new Interval(start, end), zone, rollup, null); - - List output = new ArrayList(); - for(MultiDataPoint dp : cursor) { - output.add(dp); - } - assertEquals(expected, output); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.readMultiRollupDataPoints(series, new Interval(start, end), zone, rollup, null); - - List output = new ArrayList(); - for(MultiDataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("GET", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.readMultiRollupDataPoints(series, new Interval(start, end), zone, rollup, null); - - List output = new ArrayList(); - for(MultiDataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/series/key/key/data/rollups/segment/", uri.getPath()); - } - - @Test - public void testParameters() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.readMultiRollupDataPoints(series, new Interval(start, end), zone, rollup, null); - - List output = new ArrayList(); - for(MultiDataPoint dp : cursor) { - output.add(dp); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("start", "2012-01-01T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("end", "2012-01-02T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertTrue(params.contains(new BasicNameValuePair("rollup.period", "PT1M"))); - assertTrue(params.contains(new BasicNameValuePair("rollup.fold", "sum"))); - assertTrue(params.contains(new BasicNameValuePair("rollup.fold", "max"))); - assertEquals(6, params.size()); - } - - @Test - public void testError() throws IOException { - HttpResponse response = Util.getResponse(403, "You are forbidden"); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.readMultiRollupDataPoints(series, new Interval(start, end), zone, rollup, null); - - thrown.expect(TempoDBException.class); - cursor.iterator().next(); - } -} diff --git a/src/test/java/com/tempodb/ReadSingleValueByFilterTest.java b/src/test/java/com/tempodb/ReadSingleValueByFilterTest.java deleted file mode 100644 index 839b554..0000000 --- a/src/test/java/com/tempodb/ReadSingleValueByFilterTest.java +++ /dev/null @@ -1,242 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.message.BasicNameValuePair; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.junit.*; -import static org.junit.Assert.*; -import org.junit.rules.ExpectedException; - - -public class ReadSingleValueByFilterTest { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private static final String json = "[{" + - "\"series\":{" + - "\"id\":\"id1\"," + - "\"key\":\"key1\"," + - "\"name\":\"name1\"," + - "\"tags\":[]," + - "\"attributes\":{}" + - "}," + - "\"data\":{" + - "\"t\":\"2012-01-01T00:00:01.000Z\"," + - "\"v\":12.34" + - "}," + - "\"tz\":\"UTC\"" + - "}]"; - - private static final String json1 = "[" + - "{" + - "\"series\":{" + - "\"id\":\"id1\"," + - "\"key\":\"key1\"," + - "\"name\":\"name1\"," + - "\"tags\":[]," + - "\"attributes\":{}" + - "}," + - "\"data\":{" + - "\"t\":\"2012-01-01T00:00:01.000Z\"," + - "\"v\":12.34" + - "}," + - "\"tz\":\"UTC\"" + - "}," + - "{" + - "\"series\":{" + - "\"id\":\"id2\"," + - "\"key\":\"key2\"," + - "\"name\":\"name2\"," + - "\"tags\":[]," + - "\"attributes\":{}" + - "}," + - "\"data\":{" + - "\"t\":\"2012-01-01T00:00:01.000Z\"," + - "\"v\":23.45" + - "}," + - "\"tz\":\"UTC\"" + - "}" + - "]"; - - private static final String json2 = "[" + - "{" + - "\"series\":{" + - "\"id\":\"id3\"," + - "\"key\":\"key3\"," + - "\"name\":\"name3\"," + - "\"tags\":[]," + - "\"attributes\":{}" + - "}," + - "\"data\":{" + - "\"t\":\"2012-01-01T00:00:01.000Z\"," + - "\"v\":34.56" + - "}," + - "\"tz\":\"UTC\"" + - "}" + - "]"; - - private static final String jsonTz = "[{" + - "\"series\":{" + - "\"id\":\"id1\"," + - "\"key\":\"key1\"," + - "\"name\":\"name1\"," + - "\"tags\":[]," + - "\"attributes\":{}" + - "}," + - "\"data\":{" + - "\"t\":\"2012-01-01T00:00:01.000-06:00\"," + - "\"v\":12.34" + - "}," + - "\"tz\":\"America/Chicago\"" + - "}]"; - - private static final DateTimeZone zone = DateTimeZone.UTC; - private static final Series series1 = new Series("key1", "name1", new HashSet(), new HashMap()); - private static final Series series2 = new Series("key2", "name2", new HashSet(), new HashMap()); - private static final Series series3 = new Series("key3", "name3", new HashSet(), new HashMap()); - private static final DateTime timestamp = new DateTime(2012, 1, 1, 0, 0, 1, 0, zone); - private static final Filter filter = new Filter(); - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, json); - Client client = Util.getClient(response); - - List expected = Arrays.asList(new SingleValue(series1, new DataPoint(timestamp, 12.34))); - - Cursor cursor = client.readSingleValue(filter, timestamp, zone, Direction.EXACT); - List output = new ArrayList(); - for(SingleValue value : cursor) { - output.add(value); - } - assertEquals(expected, output); - } - - @Test - public void smokeTestTz() throws IOException { - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - HttpResponse response = Util.getResponse(200, jsonTz); - Client client = Util.getClient(response); - - List expected = Arrays.asList(new SingleValue(series1, new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, 0, zone), 12.34))); - - Cursor cursor = client.readSingleValue(filter, timestamp, zone, Direction.EXACT); - List output = new ArrayList(); - for(SingleValue value : cursor) { - output.add(value); - } - assertEquals(expected, output); - } - - @Test - public void smokeTestMultipleClientCalls() throws IOException { - HttpResponse response1 = Util.getResponse(200, json1); - response1.addHeader("Link", "; rel=\"next\""); - HttpResponse response2 = Util.getResponse(200, json2); - HttpClient mockClient = Util.getMockHttpClient(response1, response2); - Client client = Util.getClient(mockClient); - - List expected = Arrays.asList( - new SingleValue(series1, new DataPoint(timestamp, 12.34)), - new SingleValue(series2, new DataPoint(timestamp, 23.45)), - new SingleValue(series3, new DataPoint(timestamp, 34.56)) - ); - - Cursor cursor = client.readSingleValue(filter, timestamp, zone, Direction.EXACT); - List output = new ArrayList(); - for(SingleValue value : cursor) { - output.add(value); - } - assertEquals(expected, output); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.readSingleValue(filter, timestamp, zone, Direction.EXACT); - List output = new ArrayList(); - for(SingleValue value : cursor) { - output.add(value); - } - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("GET", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.readSingleValue(filter, timestamp, zone, Direction.EXACT); - List output = new ArrayList(); - for(SingleValue value : cursor) { - output.add(value); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/single/", uri.getPath()); - } - - @Test - public void testParameters() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Filter filter = new Filter(); - filter.addKey("key1"); - filter.addTag("tag1"); - filter.addTag("tag1"); - filter.addAttribute("key1", "value1"); - filter.addAttribute("key2", "value2"); - - Cursor cursor = client.readSingleValue(filter, timestamp, zone, Direction.EXACT); - List output = new ArrayList(); - for(SingleValue value : cursor) { - output.add(value); - } - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("ts", "2012-01-01T00:00:01.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("key", "key1"))); - assertTrue(params.contains(new BasicNameValuePair("tag", "tag1"))); - assertTrue(params.contains(new BasicNameValuePair("attr[key1]", "value1"))); - assertTrue(params.contains(new BasicNameValuePair("attr[key2]", "value2"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertTrue(params.contains(new BasicNameValuePair("direction", "exact"))); - assertEquals(7, params.size()); - } - - @Test - public void testError() throws IOException { - HttpResponse response = Util.getResponse(403, "You are forbidden"); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Cursor cursor = client.readSingleValue(filter, timestamp, zone, Direction.EXACT); - - thrown.expect(TempoDBException.class); - cursor.iterator().next(); - } -} diff --git a/src/test/java/com/tempodb/ReadSingleValueBySeriesTest.java b/src/test/java/com/tempodb/ReadSingleValueBySeriesTest.java deleted file mode 100644 index d580ab0..0000000 --- a/src/test/java/com/tempodb/ReadSingleValueBySeriesTest.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.message.BasicNameValuePair; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; -import org.junit.rules.ExpectedException; - - -public class ReadSingleValueBySeriesTest { - private static final DateTimeZone zone = DateTimeZone.UTC; - private static final Series series = new Series("key1"); - private static final DateTime timestamp = new DateTime(2012, 1, 1, 0, 0, 1, 0, zone); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private static final String json = "{" + - "\"series\":{" + - "\"id\":\"id1\"," + - "\"key\":\"key1\"," + - "\"name\":\"\"," + - "\"tags\":[]," + - "\"attributes\":{}" + - "}," + - "\"data\":{" + - "\"t\":\"2012-01-01T00:00:01.000Z\"," + - "\"v\":12.34" + - "}," + - "\"tz\":\"UTC\"" + - "}"; - - private static final String jsonTz = "{" + - "\"series\":{" + - "\"id\":\"id1\"," + - "\"key\":\"key1\"," + - "\"name\":\"\"," + - "\"tags\":[]," + - "\"attributes\":{}" + - "}," + - "\"data\":{" + - "\"t\":\"2012-01-01T00:00:01.000-06:00\"," + - "\"v\":12.34" + - "}," + - "\"tz\":\"America/Chicago\"" + - "}"; - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, json); - Client client = Util.getClient(response); - DateTime timestamp = new DateTime(2012, 1, 1, 0, 0, 1, 0, zone); - - Result result = client.readSingleValue(series, timestamp, zone); - - DataPoint datapoint = new DataPoint(timestamp, 12.34); - Result expected = new Result(new SingleValue(series, datapoint), 200, "OK"); - assertEquals(expected, result); - } - - @Test - public void smokeTestTz() throws IOException { - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - HttpResponse response = Util.getResponse(200, jsonTz); - Client client = Util.getClient(response); - DateTime timestamp = new DateTime(2012, 1, 1, 0, 0, 1, 0, zone); - - Result result = client.readSingleValue(series, timestamp, zone); - - DataPoint datapoint = new DataPoint(timestamp, 12.34); - Result expected = new Result(new SingleValue(series, datapoint), 200, "OK"); - assertEquals(expected, result); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.readSingleValue(series, timestamp, zone); - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("GET", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.readSingleValue(series, timestamp, zone); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/series/key/key1/single/", uri.getPath()); - } - - @Test - public void testParameters() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.readSingleValue(series, timestamp, zone, Direction.NEAREST); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("ts", "2012-01-01T00:00:01.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertTrue(params.contains(new BasicNameValuePair("direction", "nearest"))); - assertEquals(3, params.size()); - } -} diff --git a/src/test/java/com/tempodb/ReadSummaryTest.java b/src/test/java/com/tempodb/ReadSummaryTest.java deleted file mode 100644 index d4ce952..0000000 --- a/src/test/java/com/tempodb/ReadSummaryTest.java +++ /dev/null @@ -1,136 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.utils.URLEncodedUtils; -import org.apache.http.message.BasicNameValuePair; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; -import org.junit.*; -import static org.junit.Assert.*; -import org.junit.rules.ExpectedException; - - -public class ReadSummaryTest { - private static final DateTimeZone zone = DateTimeZone.UTC; - private static final Series series = new Series("key1"); - private static final Interval interval = new Interval(new DateTime(2012, 1, 1, 0, 0, 0, 0, zone), new DateTime(2012, 1, 2, 0, 0, 0, 0, zone)); - - private static final Map data; - static { - data = new HashMap(); - data.put("max", 12.34); - data.put("min", 23.45); - } - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private static final String json = "{" + - "\"summary\":{" + - "\"max\":12.34," + - "\"min\":23.45" + - "}," + - "\"tz\":\"UTC\"," + - "\"start\":\"2012-01-01T00:00:00.000Z\"," + - "\"end\":\"2012-01-02T00:00:00.000Z\"," + - "\"series\":{" + - "\"id\":\"id1\"," + - "\"key\":\"key1\"," + - "\"name\":\"\"," + - "\"tags\":[]," + - "\"attributes\":{}" + - "}" + - "}"; - - private static final String jsonTz = "{" + - "\"summary\":{" + - "\"max\":12.34," + - "\"min\":23.45" + - "}," + - "\"tz\":\"America/Chicago\"," + - "\"start\":\"2012-01-01T00:00:00.000-06:00\"," + - "\"end\":\"2012-01-02T00:00:00.000-06:00\"," + - "\"series\":{" + - "\"id\":\"id1\"," + - "\"key\":\"key1\"," + - "\"name\":\"\"," + - "\"tags\":[]," + - "\"attributes\":{}" + - "}" + - "}"; - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, json); - Client client = Util.getClient(response); - - Result result = client.readSummary(series, interval); - - Result expected = new Result(new Summary(series, interval, data), 200, "OK"); - assertEquals(expected, result); - } - - @Test - public void smokeTestTz() throws IOException { - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - HttpResponse response = Util.getResponse(200, jsonTz); - Client client = Util.getClient(response); - Interval interval = new Interval(new DateTime(2012, 1, 1, 0, 0, 0, 0, zone), new DateTime(2012, 1, 2, 0, 0, 0, 0, zone)); - - Result result = client.readSummary(series, interval); - - Result expected = new Result(new Summary(series, interval, data), 200, "OK"); - assertEquals(expected, result); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.readSummary(series, interval); - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("GET", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.readSummary(series, interval); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/series/key/key1/summary/", uri.getPath()); - } - - @Test - public void testParameters() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.readSummary(series, interval); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - List params = URLEncodedUtils.parse(uri, "UTF-8"); - assertTrue(params.contains(new BasicNameValuePair("start", "2012-01-01T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("end", "2012-01-02T00:00:00.000+0000"))); - assertTrue(params.contains(new BasicNameValuePair("tz", "UTC"))); - assertEquals(3, params.size()); - } -} diff --git a/src/test/java/com/tempodb/ResultTest.java b/src/test/java/com/tempodb/ResultTest.java deleted file mode 100644 index 86d9b8b..0000000 --- a/src/test/java/com/tempodb/ResultTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.util.Arrays; - -import org.apache.http.HttpResponse; -import org.junit.*; -import static org.junit.Assert.*; - - -public class ResultTest { - - @Test - public void testConstructor() { - Result result = new Result(1L, 200, "message"); - assertEquals(200, result.getCode()); - assertEquals("message", result.getMessage()); - } - - @Test - public void testEquals() { - Result result = new Result(1L, 200, "message"); - Result expected = new Result(1L, 200, "message"); - assertEquals(expected, result); - } - - @Test - public void testNotEquals() { - Result result1 = new Result(1L, 200, "message"); - Result result2 = new Result(2L, 100, "message"); - Result result3 = new Result(2L, 200, "message1"); - Result expected = new Result(2L, 200, "message"); - assertFalse(expected.equals(result1)); - assertFalse(expected.equals(result2)); - assertFalse(expected.equals(result3)); - } - - @Test - public void testSuccessfulRequest() throws IOException { - HttpResponse response = Util.getResponse(200, ""); - Result result = new Result(response, Void.class); - Result expected = new Result(null, 200, "OK", null); - assertEquals(expected, result); - assertTrue(result.getState() == State.SUCCESS); - } - - @Test - public void testFailedRequest_Body() throws IOException { - HttpResponse response = Util.getResponse(403, "You are forbidden"); - Result result = new Result(response, Void.class); - Result expected = new Result(null, 403, "You are forbidden", null); - assertEquals(expected, result); - assertTrue(result.getState() == State.FAILURE); - } - - @Test - public void testFailedRequest_NoBody() throws IOException { - HttpResponse response = Util.getResponse(403, ""); - Result result = new Result(response, Void.class); - Result expected = new Result(null, 403, "Forbidden", null); - assertEquals(expected, result); - assertTrue(result.getState() == State.FAILURE); - } - - @Test - public void testPartialFailure() throws IOException { - String json = "{\"multistatus\":[{\"status\":403,\"messages\":[\"Forbidden\"]}]}"; - HttpResponse response = Util.getResponse(207, json); - Result result = new Result(response, Void.class); - - MultiStatus multistatus = new MultiStatus(Arrays.asList(new Status(403, Arrays.asList("Forbidden")))); - Result expected = new Result(null, 207, "Multi-Status", multistatus); - assertEquals(expected, result); - assertTrue(result.getState() == State.PARTIAL_SUCCESS); - } -} diff --git a/src/test/java/com/tempodb/RollupTest.java b/src/test/java/com/tempodb/RollupTest.java deleted file mode 100644 index 572e011..0000000 --- a/src/test/java/com/tempodb/RollupTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.tempodb; - -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; - - -public class RollupTest { - - @Test - public void testEquals() { - Rollup r1 = new Rollup(Period.minutes(1), Fold.SUM); - Rollup r2 = new Rollup(Period.minutes(1), Fold.SUM); - assertEquals(r1, r2); - } - - @Test - public void testNotEquals_Period() { - Rollup r1 = new Rollup(Period.minutes(1), Fold.SUM); - Rollup r2 = new Rollup(Period.minutes(2), Fold.SUM); - assertFalse(r1.equals(r2)); - } - - @Test - public void testNotEquals_Fold() { - Rollup r1 = new Rollup(Period.minutes(1), Fold.SUM); - Rollup r2 = new Rollup(Period.minutes(1), Fold.MEAN); - assertFalse(r1.equals(r2)); - } - - @Test - public void testNotEquals_Null() { - Rollup r1 = new Rollup(Period.minutes(1), Fold.SUM); - assertFalse(r1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/SeriesSegmentTest.java b/src/test/java/com/tempodb/SeriesSegmentTest.java deleted file mode 100644 index d729d13..0000000 --- a/src/test/java/com/tempodb/SeriesSegmentTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.tempodb; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; - -import org.junit.*; -import static org.junit.Assert.*; - - -public class SeriesSegmentTest { - - private static final List data1 = Arrays.asList(new Series("key", "name", new HashSet(), new HashMap())); - private static final List data2 = Arrays.asList(new Series("key", "name", new HashSet(), new HashMap())); - private static final List data3 = Arrays.asList(new Series("key3", "name3", new HashSet(), new HashMap())); - - @Test - public void testEquals() { - SeriesSegment segment1 = new SeriesSegment(data1, null); - SeriesSegment segment2 = new SeriesSegment(data2, null); - assertEquals(segment1, segment2); - } - - @Test - public void testNotEquals_Data() { - SeriesSegment segment1 = new SeriesSegment(data1, null); - SeriesSegment segment2 = new SeriesSegment(data3, null); - assertFalse(segment1.equals(segment2)); - } - - @Test - public void testNotEquals_Next() { - SeriesSegment segment1 = new SeriesSegment(data1, "next1"); - SeriesSegment segment2 = new SeriesSegment(data2, "next2"); - assertFalse(segment1.equals(segment2)); - } - - @Test - public void testNotEquals_Null() { - SeriesSegment segment1 = new SeriesSegment(data1, "next1"); - assertFalse(segment1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/SeriesTest.java b/src/test/java/com/tempodb/SeriesTest.java deleted file mode 100644 index a35f73c..0000000 --- a/src/test/java/com/tempodb/SeriesTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.tempodb; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; - -import org.junit.*; -import static org.junit.Assert.*; - - -public class SeriesTest { - - private static final Set tags = new LinkedHashSet(Arrays.asList("tag1", "tag2")); - private static final Map attributes; - static { - Map map = new HashMap(); - map.put("key1", "value1"); - map.put("key2", "value2"); - attributes = Collections.unmodifiableMap(map); - } - - @Test - public void testEquals() { - Series s1 = new Series("key", "name", tags, attributes); - Series s2 = new Series("key", "name", tags, attributes); - assertEquals(s1, s2); - } - - @Test - public void testNotEquals_Key() { - Series s1 = new Series("key1", "name", tags, attributes); - Series s2 = new Series("key2", "name", tags, attributes); - assertFalse(s1.equals(s2)); - } - - @Test - public void testNotEquals_Name() { - Series s1 = new Series("key", "name1", tags, attributes); - Series s2 = new Series("key", "name2", tags, attributes); - assertFalse(s1.equals(s2)); - } - - @Test - public void testNotEquals_Tags() { - Set tags2 = new LinkedHashSet(); - tags.add("tag1"); - - Series s1 = new Series("key", "name", tags, attributes); - Series s2 = new Series("key", "name", tags2, attributes); - assertFalse(s1.equals(s2)); - } - - @Test - public void testNotEquals_Attributes() { - Map attributes2 = new HashMap(); - attributes2.put("key1", "value1"); - - Series s1 = new Series("key", "name", tags, attributes); - Series s2 = new Series("key", "name", tags, attributes2); - assertFalse(s1.equals(s2)); - } - - @Test - public void testNotEquals_Null() { - Series s1 = new Series("key", "name1", tags, attributes); - assertFalse(s1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/SingleValueSegmentTest.java b/src/test/java/com/tempodb/SingleValueSegmentTest.java deleted file mode 100644 index 40cf955..0000000 --- a/src/test/java/com/tempodb/SingleValueSegmentTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.tempodb; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; - -import org.joda.time.DateTime; -import org.junit.*; -import static org.junit.Assert.*; - - -public class SingleValueSegmentTest { - - private static final DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - private static final DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - private static final DataPoint dp3 = new DataPoint(new DateTime(2012, 1, 2, 0, 0, 0, 0), 10.34); - - private static final List data1 = Arrays.asList(new SingleValue(new Series("key"), dp1)); - private static final List data2 = Arrays.asList(new SingleValue(new Series("key"), dp2)); - private static final List data3 = Arrays.asList(new SingleValue(new Series("key3"), dp3)); - - @Test - public void testEquals() { - SingleValueSegment segment1 = new SingleValueSegment(data1); - SingleValueSegment segment2 = new SingleValueSegment(data2); - assertEquals(segment1, segment2); - } - - @Test - public void testNotEquals_Data() { - SingleValueSegment segment1 = new SingleValueSegment(data1, null); - SingleValueSegment segment2 = new SingleValueSegment(data3, null); - assertFalse(segment1.equals(segment2)); - } - - @Test - public void testNotEquals_Next() { - SingleValueSegment segment1 = new SingleValueSegment(data1, "next1"); - SingleValueSegment segment2 = new SingleValueSegment(data2, "next2"); - assertFalse(segment1.equals(segment2)); - } - - @Test - public void testNotEquals_Null() { - SingleValueSegment segment1 = new SingleValueSegment(data1, "next1"); - assertFalse(segment1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/SingleValueTest.java b/src/test/java/com/tempodb/SingleValueTest.java deleted file mode 100644 index 759bd32..0000000 --- a/src/test/java/com/tempodb/SingleValueTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.tempodb; - -import org.joda.time.DateTime; -import org.junit.*; -import static org.junit.Assert.*; - - -public class SingleValueTest { - - private static final Series series1 = new Series("key1"); - private static final Series series2 = new Series("key1"); - private static final Series series3 = new Series("key2"); - - private static final DataPoint dp1 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - private static final DataPoint dp2 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - private static final DataPoint dp3 = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0), 10.34); - - @Test - public void testEquals() { - SingleValue sv1 = new SingleValue(series1, dp1); - SingleValue sv2 = new SingleValue(series2, dp2); - assertEquals(sv1, sv2); - } - - @Test - public void testNotEquals_Series() { - SingleValue sv1 = new SingleValue(series1, dp1); - SingleValue sv2 = new SingleValue(series3, dp2); - assertFalse(sv1.equals(sv2)); - } - - @Test - public void testNotEquals_DataPoint() { - SingleValue sv1 = new SingleValue(series1, dp1); - SingleValue sv2 = new SingleValue(series2, dp3); - assertFalse(sv1.equals(sv2)); - } - - @Test - public void testNotEquals_Null() { - SingleValue sv1 = new SingleValue(series1, dp1); - assertFalse(sv1.equals(null)); - } -} - diff --git a/src/test/java/com/tempodb/StatusTest.java b/src/test/java/com/tempodb/StatusTest.java deleted file mode 100644 index 1ab97e0..0000000 --- a/src/test/java/com/tempodb/StatusTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.tempodb; - -import java.util.Arrays; - -import org.junit.*; -import static org.junit.Assert.*; - - -public class StatusTest { - - @Test - public void testEquals() { - Status s1 = new Status(1, Arrays.asList("message")); - Status s2 = new Status(1, Arrays.asList("message")); - assertEquals(s1, s2); - } - - @Test - public void testNotEquals_Code() { - Status s1 = new Status(1, Arrays.asList("message")); - Status s2 = new Status(2, Arrays.asList("message")); - assertFalse(s1.equals(s2)); - } - - @Test - public void testNotEquals_Messages() { - Status s1 = new Status(1, Arrays.asList("message1")); - Status s2 = new Status(1, Arrays.asList("message2")); - assertFalse(s1.equals(s2)); - } - - @Test - public void testNotEquals_Null() { - Status s1 = new Status(1, Arrays.asList("message")); - assertFalse(s1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/SummaryTest.java b/src/test/java/com/tempodb/SummaryTest.java deleted file mode 100644 index 8431ded..0000000 --- a/src/test/java/com/tempodb/SummaryTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.tempodb; - -import java.util.HashMap; -import java.util.Map; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; -import org.junit.*; -import static org.junit.Assert.*; - - -public class SummaryTest { - - private static final Series series1 = new Series("key1"); - private static final Series series2 = new Series("key1"); - private static final Series series3 = new Series("key2"); - - private static final DateTime dt1 = new DateTime(2012, 1, 1, 0, 0, 0, 0); - private static final DateTime dt2 = new DateTime(2012, 1, 1, 0, 0, 0, 0); - private static final DateTime dt3 = new DateTime(2012, 1, 2, 0, 0, 0, 0); - - private static final Map data1; - private static final Map data2; - private static final Map data3; - static { - data1 = new HashMap(); - data1.put("max", 12.34); - data1.put("min", 23.45); - - data2 = new HashMap(); - data2.put("max", 12.34); - data2.put("min", 23.45); - - data3 = new HashMap(); - data3.put("max", 12.34); - data3.put("min", 45.67); - } - - @Test - public void testEquals() { - Summary s1 = new Summary(series1, new Interval(dt1, dt1), data1); - Summary s2 = new Summary(series2, new Interval(dt2, dt2), data2); - assertEquals(s1, s2); - } - - @Test - public void testNotEquals_Series() { - Summary s1 = new Summary(series1, new Interval(dt1, dt1), data1); - Summary s2 = new Summary(series3, new Interval(dt2, dt2), data2); - assertFalse(s1.equals(s2)); - } - - @Test - public void testNotEquals_Interval() { - Summary s1 = new Summary(series1, new Interval(dt1, dt1), data1); - Summary s2 = new Summary(series2, new Interval(dt2, dt3), data2); - assertFalse(s1.equals(s2)); - } - - @Test - public void testNotEquals_Data() { - Summary s1 = new Summary(series1, new Interval(dt1, dt1), data1); - Summary s2 = new Summary(series2, new Interval(dt2, dt2), data3); - assertFalse(s1.equals(s2)); - } - - @Test - public void testNotEquals_Null() { - Summary s1 = new Summary(series1, new Interval(dt1, dt1), data1); - assertFalse(s1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/UpdateSeriesTest.java b/src/test/java/com/tempodb/UpdateSeriesTest.java deleted file mode 100644 index f619e3a..0000000 --- a/src/test/java/com/tempodb/UpdateSeriesTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.nio.charset.Charset; -import java.net.URISyntaxException; -import java.util.HashMap; -import java.util.HashSet; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.protocol.HttpContext; -import org.apache.http.util.EntityUtils; -import org.junit.*; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; -import org.mockito.ArgumentCaptor; - - -public class UpdateSeriesTest { - - private static final String json = "{\"id\":\"id1\",\"key\":\"key1\",\"name\":\"name1\",\"tags\":[],\"attributes\":{}}"; - private static final String body = "{\"key\":\"key1\",\"name\":\"name1\",\"tags\":[],\"attributes\":{}}"; - private static final Series series = new Series("key1", "name1", new HashSet(), new HashMap()); - private static final Series series1 = new Series("key1", "name1", new HashSet(), new HashMap()); - - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, json); - Client client = Util.getClient(response); - - Result result = client.updateSeries(series); - - assertEquals(series1, result.getValue()); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.updateSeries(series); - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("PUT", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.updateSeries(series); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/series/key/key1/", uri.getPath()); - } - - @Test - public void testBody() throws IOException { - HttpResponse response = Util.getResponse(200, json); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.updateSeries(series); - - ArgumentCaptor argument = ArgumentCaptor.forClass(HttpPut.class); - verify(mockClient).execute(any(HttpHost.class), argument.capture(), any(HttpContext.class)); - assertEquals(body, EntityUtils.toString(argument.getValue().getEntity(), DEFAULT_CHARSET)); - } -} diff --git a/src/test/java/com/tempodb/Util.java b/src/test/java/com/tempodb/Util.java deleted file mode 100644 index e4dbd1b..0000000 --- a/src/test/java/com/tempodb/Util.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.nio.charset.Charset; -import java.util.Locale; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.EnglishReasonPhraseCatalog; -import org.apache.http.message.*; -import org.apache.http.protocol.HttpContext; -import static org.mockito.Mockito.*; -import org.mockito.ArgumentCaptor; - - -public class Util { - - public static Client getClient(HttpClient httpClient) { - InetSocketAddress host = new InetSocketAddress("example.com", 80); - Client client = new Client(new Database("id"), new Credentials("key", "secret"), host, "http"); - client.setHttpClient(httpClient); - return client; - } - - public static Client getClient(HttpResponse response) throws IOException { - HttpClient mockClient = getMockHttpClient(response); - Client client = getClient(mockClient); - return client; - } - - public static HttpClient getMockHttpClient(HttpResponse response) throws IOException { - HttpClient mockHttpClient = mock(HttpClient.class); - when(mockHttpClient.execute(any(HttpHost.class), any(HttpRequest.class), any(HttpContext.class))).thenReturn(response); - return mockHttpClient; - } - - public static HttpClient getMockHttpClient(HttpResponse response, HttpResponse... responses) throws IOException { - HttpClient mockHttpClient = mock(HttpClient.class); - when(mockHttpClient.execute(any(HttpHost.class), any(HttpRequest.class), any(HttpContext.class))).thenReturn(response, responses); - return mockHttpClient; - } - - public static HttpResponse getResponse(int expectedStatus, String expectedBody) { - ProtocolVersion version = new ProtocolVersion("HTTP", 1, 1); - StatusLine statusLine = new BasicStatusLine(version, expectedStatus, EnglishReasonPhraseCatalog.INSTANCE.getReason(expectedStatus, Locale.US)); - HttpResponse response = new BasicHttpResponse(statusLine); - response.setEntity(new StringEntity(expectedBody, Charset.forName("UTF-8"))); - return response; - } - - public static HttpRequest captureRequest(HttpClient client) throws IOException { - ArgumentCaptor argument = ArgumentCaptor.forClass(HttpRequest.class); - verify(client).execute(any(HttpHost.class), argument.capture(), any(HttpContext.class)); - return argument.getValue(); - } -} diff --git a/src/test/java/com/tempodb/WritableDataPointTest.java b/src/test/java/com/tempodb/WritableDataPointTest.java deleted file mode 100644 index 6d83b41..0000000 --- a/src/test/java/com/tempodb/WritableDataPointTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.tempodb; - -import org.joda.time.DateTime; -import org.junit.*; -import static org.junit.Assert.*; - - -public class WritableDataPointTest { - - @Test - public void testEquals() { - WritableDataPoint wdp1 = new WritableDataPoint(new Series("key"), new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - WritableDataPoint wdp2 = new WritableDataPoint(new Series("key"), new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - assertEquals(wdp1, wdp2); - } - - @Test - public void testNotEquals_Key() { - WritableDataPoint wdp1 = new WritableDataPoint(new Series("key1"), new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - WritableDataPoint wdp2 = new WritableDataPoint(new Series("key2"), new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - assertFalse(wdp1.equals(wdp2)); - } - - @Test - public void testNotEquals_Timestamp() { - WritableDataPoint wdp1 = new WritableDataPoint(new Series("key"), new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - WritableDataPoint wdp2 = new WritableDataPoint(new Series("key"), new DateTime(2012, 1, 2, 0, 0, 0, 0), 12.34); - assertFalse(wdp1.equals(wdp2)); - } - - @Test - public void testNotEquals_Value() { - WritableDataPoint wdp1 = new WritableDataPoint(new Series("key"), new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - WritableDataPoint wdp2 = new WritableDataPoint(new Series("key"), new DateTime(2012, 1, 1, 0, 0, 0, 0), 23.45); - assertFalse(wdp1.equals(wdp2)); - } - - @Test - public void testNotEquals_Null() { - WritableDataPoint wdp1 = new WritableDataPoint(new Series("key"), new DateTime(2012, 1, 1, 0, 0, 0, 0), 12.34); - assertFalse(wdp1.equals(null)); - } -} diff --git a/src/test/java/com/tempodb/WriteDataPointsBySeriesTest.java b/src/test/java/com/tempodb/WriteDataPointsBySeriesTest.java deleted file mode 100644 index 4968ba7..0000000 --- a/src/test/java/com/tempodb/WriteDataPointsBySeriesTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.nio.charset.Charset; -import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.List; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.protocol.HttpContext; -import org.apache.http.util.EntityUtils; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.junit.*; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; -import org.mockito.ArgumentCaptor; - - -public class WriteDataPointsBySeriesTest { - - private static final String json = "[" + - "{\"t\":\"2012-03-27T05:00:00.000Z\",\"v\":12.34}," + - "{\"t\":\"2012-03-27T05:01:00.000Z\",\"v\":23.45}" + - "]"; - - private static final DateTimeZone timezone = DateTimeZone.UTC; - private static final List data = Arrays.asList(new DataPoint(new DateTime(2012, 3, 27, 5, 0, 0, 0, timezone), 12.34), - new DataPoint(new DateTime(2012, 3, 27, 5, 1, 0, 0, timezone), 23.45)); - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - private static final Series series = new Series("key1"); - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, ""); - Client client = Util.getClient(response); - Result result = client.writeDataPoints(series, data); - - Result expected = new Result(null, 200, "OK"); - assertEquals(expected, result); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, ""); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.writeDataPoints(series, data); - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("POST", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, ""); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.writeDataPoints(series, data); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/series/key/key1/data/", uri.getPath()); - } - - @Test - public void testBody() throws IOException { - HttpResponse response = Util.getResponse(200, ""); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.writeDataPoints(series, data); - - ArgumentCaptor argument = ArgumentCaptor.forClass(HttpPost.class); - verify(mockClient).execute(any(HttpHost.class), argument.capture(), any(HttpContext.class)); - assertEquals(json, EntityUtils.toString(argument.getValue().getEntity(), DEFAULT_CHARSET)); - } -} diff --git a/src/test/java/com/tempodb/WriteDataPointsTest.java b/src/test/java/com/tempodb/WriteDataPointsTest.java deleted file mode 100644 index 67cd2d4..0000000 --- a/src/test/java/com/tempodb/WriteDataPointsTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.tempodb; - -import java.io.IOException; -import java.net.URI; -import java.nio.charset.Charset; -import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.List; - -import org.apache.http.*; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.protocol.HttpContext; -import org.apache.http.util.EntityUtils; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.junit.*; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; -import org.mockito.ArgumentCaptor; - - -public class WriteDataPointsTest { - - private static final String json = "[" + - "{\"key\":\"key1\",\"t\":\"2012-03-27T05:00:00.000Z\",\"v\":12.34}," + - "{\"key\":\"key2\",\"t\":\"2012-03-27T05:01:00.000Z\",\"v\":23.45}" + - "]"; - - private static final String multistatus_json = "{\"multistatus\":[{\"status\":403,\"messages\":[\"Forbidden\"]}]}"; - - private static final DateTimeZone timezone = DateTimeZone.UTC; - private static final WriteRequest wr = new WriteRequest() - .add(new Series("key1"), new DataPoint(new DateTime(2012, 3, 27, 5, 0, 0, 0, timezone), 12.34)) - .add(new Series("key2"), new DataPoint(new DateTime(2012, 3, 27, 5, 1, 0, 0, timezone), 23.45)); - - private static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); - - @Test - public void smokeTest() throws IOException { - HttpResponse response = Util.getResponse(200, ""); - Client client = Util.getClient(response); - Result result = client.writeDataPoints(wr); - - Result expected = new Result(null, 200, "OK"); - assertEquals(expected, result); - assertEquals("OK", result.getMessage()); - } - - @Test - public void testMethod() throws IOException { - HttpResponse response = Util.getResponse(200, ""); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.writeDataPoints(wr); - - HttpRequest request = Util.captureRequest(mockClient); - assertEquals("POST", request.getRequestLine().getMethod()); - } - - @Test - public void testUri() throws IOException, URISyntaxException { - HttpResponse response = Util.getResponse(200, ""); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.writeDataPoints(wr); - - HttpRequest request = Util.captureRequest(mockClient); - URI uri = new URI(request.getRequestLine().getUri()); - assertEquals("/v1/multi/", uri.getPath()); - } - - @Test - public void testBody() throws IOException { - HttpResponse response = Util.getResponse(200, ""); - HttpClient mockClient = Util.getMockHttpClient(response); - Client client = Util.getClient(mockClient); - - Result result = client.writeDataPoints(wr); - - ArgumentCaptor argument = ArgumentCaptor.forClass(HttpPost.class); - verify(mockClient).execute(any(HttpHost.class), argument.capture(), any(HttpContext.class)); - assertEquals(json, EntityUtils.toString(argument.getValue().getEntity(), DEFAULT_CHARSET)); - } - - @Test - public void testMultiStatus() throws IOException { - HttpResponse response = Util.getResponse(207, multistatus_json); - Client client = Util.getClient(response); - - Result result = client.writeDataPoints(wr); - MultiStatus multistatus = new MultiStatus(Arrays.asList(new Status(403, Arrays.asList("Forbidden")))); - - Result expected = new Result(null, 207, "Multi-Status", multistatus); - assertEquals(expected, result); - } -} diff --git a/src/test/java/com/tempodb/WriteRequestTest.java b/src/test/java/com/tempodb/WriteRequestTest.java deleted file mode 100644 index 3f6efca..0000000 --- a/src/test/java/com/tempodb/WriteRequestTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.tempodb; - -import java.util.Arrays; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.junit.*; -import static org.junit.Assert.*; - - -public class WriteRequestTest { - private static final DateTimeZone timezone = DateTimeZone.UTC; - - private static final Series series1 = new Series("key1"); - private static final Series series2 = new Series("key1"); - private static final Series series3 = new Series("key2"); - - private static final DataPoint dp1 = new DataPoint(new DateTime(2102, 1, 1, 0, 0, 0, 0, timezone), 12.34); - private static final DataPoint dp2 = new DataPoint(new DateTime(2102, 1, 1, 0, 0, 0, 0, timezone), 12.34); - private static final DataPoint dp3 = new DataPoint(new DateTime(2102, 1, 1, 0, 0, 0, 0, timezone), 23.45); - - @Test - public void testEquals() { - WriteRequest wr1 = new WriteRequest().add(series1, dp1); - WriteRequest wr2 = new WriteRequest().add(series2, dp2); - assertEquals(wr1, wr2); - } - - @Test - public void testNotEquals_Series() { - WriteRequest wr1 = new WriteRequest().add(series1, dp1); - WriteRequest wr2 = new WriteRequest().add(series3, dp2); - assertFalse(wr1.equals(wr2)); - } - - @Test - public void testNotEquals_DataPoint() { - WriteRequest wr1 = new WriteRequest().add(series1, dp1); - WriteRequest wr2 = new WriteRequest().add(series2, dp3); - assertFalse(wr1.equals(wr2)); - } - - @Test - public void testNotEquals_Null() { - WriteRequest wr = new WriteRequest().add(series1, dp1); - assertFalse(wr.equals(null)); - } - - @Test - public void testAddMultiple() { - WriteRequest wr1 = new WriteRequest().add(series1, Arrays.asList(dp2, dp3)); - WriteRequest wr2 = new WriteRequest().add(series1, dp2).add(series1, dp3); - assertEquals(wr1, wr2); - } -} diff --git a/src/test/java/com/tempodb/http/PageLinksTest.java b/src/test/java/com/tempodb/http/PageLinksTest.java deleted file mode 100644 index 4039544..0000000 --- a/src/test/java/com/tempodb/http/PageLinksTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.tempodb.http; - -import org.apache.http.HttpResponse; -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.Util; - - -public class PageLinksTest { - - @Test - public void testLinkHeader() { - String header = "; rel=\"next\""; - HttpResponse response = Util.getResponse(200, ""); - response.setHeader("Link", header); - - PageLinks pageLinks = new PageLinks(response); - String expected = "/v1/series/id/id1/data/segment/?start=2012-03-27T00:02:00.000-05:00&end=2012-03-28"; - assertEquals(expected, pageLinks.getNext()); - } - - @Test - public void testMissingLinkHeader() { - HttpResponse response = Util.getResponse(200, ""); - - PageLinks pageLinks = new PageLinks(response); - String expected = ""; - assertEquals(expected, pageLinks.getNext()); - } - - @Test - public void testLinkNext() { - String header = "; rel=\"last\""; - HttpResponse response = Util.getResponse(200, ""); - response.setHeader("Link", header); - - PageLinks pageLinks = new PageLinks(response); - String expected = ""; - assertEquals(expected, pageLinks.getNext()); - } -} diff --git a/src/test/java/com/tempodb/json/DataPointFoundSegmentTest.java b/src/test/java/com/tempodb/json/DataPointFoundSegmentTest.java deleted file mode 100644 index 8064736..0000000 --- a/src/test/java/com/tempodb/json/DataPointFoundSegmentTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.DataPoint; -import com.tempodb.DataPointFound; -import com.tempodb.DataPointFoundSegment; -import com.tempodb.Predicate; - - -public class DataPointFoundSegmentTest { - - @Test - public void testDeserializeUTC() throws IOException { - String json = "{" + - "\"predicate\":{" + - "\"function\":\"max\"," + - "\"period\":\"PT1H\"" + - "}," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"interval\":{\"start\":\"2012-03-28T00:00:00.000+00:00\",\"end\":\"2012-03-29T00:00:00.000+00:00\"},\"found\":{\"t\":\"2012-03-28T23:59:00.000Z\",\"v\":2879.0}}" + - "]" + - "}"; - - DateTimeZone zone = DateTimeZone.UTC; - DataPointFoundSegment segment = Json.loads(json, DataPointFoundSegment.class); - - Interval interval = new Interval(new DateTime(2012, 3, 28, 0, 0, 0, 0, zone), new DateTime(2012, 3, 29, 0, 0, 0, 0, zone)); - DataPoint datapoint = new DataPoint(new DateTime(2012, 3, 28, 23, 59, 0, 0, zone), 2879.0); - List data = Arrays.asList(new DataPointFound(interval, datapoint)); - Predicate predicate = new Predicate(Period.hours(1), "max"); - DataPointFoundSegment expected = new DataPointFoundSegment(data, null, zone, predicate); - assertEquals(expected, segment); - } - - @Test - public void testDeserializeTZ() throws IOException { - String json = "{" + - "\"predicate\":{" + - "\"function\":\"max\"," + - "\"period\":\"PT1H\"" + - "}," + - "\"tz\":\"America/Chicago\"," + - "\"data\":[" + - "{\"interval\":{\"start\":\"2012-03-28T00:00:00.000+00:00\",\"end\":\"2012-03-29T00:00:00.000+00:00\"},\"found\":{\"t\":\"2012-03-28T23:59:00.000-05:00\",\"v\":2879.0}}" + - "]" + - "}"; - - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - DataPointFoundSegment segment = Json.loads(json, DataPointFoundSegment.class); - - Interval interval = new Interval(new DateTime(2012, 3, 27, 19, 0, 0, 0, zone), new DateTime(2012, 3, 28, 19, 0, 0, 0, zone)); - DataPoint datapoint = new DataPoint(new DateTime(2012, 3, 28, 23, 59, 0, 0, zone), 2879.0); - List data = Arrays.asList(new DataPointFound(interval, datapoint)); - Predicate predicate = new Predicate(Period.hours(1), "max"); - DataPointFoundSegment expected = new DataPointFoundSegment(data, null, zone, predicate); - assertEquals(expected, segment); - } - - @Test - public void testDeserializeRollupNull() throws IOException { - String json = "{" + - "\"predicate\":null," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"interval\":{\"start\":\"2012-03-28T00:00:00.000+00:00\",\"end\":\"2012-03-29T00:00:00.000+00:00\"},\"found\":{\"t\":\"2012-03-28T23:59:00.000Z\",\"v\":2879.0}}" + - "]" + - "}"; - - DateTimeZone zone = DateTimeZone.UTC; - DataPointFoundSegment segment = Json.loads(json, DataPointFoundSegment.class); - - Interval interval = new Interval(new DateTime(2012, 3, 28, 0, 0, 0, 0, zone), new DateTime(2012, 3, 29, 0, 0, 0, 0, zone)); - DataPoint datapoint = new DataPoint(new DateTime(2012, 3, 28, 23, 59, 0, 0, zone), 2879.0); - List data = Arrays.asList(new DataPointFound(interval, datapoint)); - Predicate predicate = null; - DataPointFoundSegment expected = new DataPointFoundSegment(data, null, zone, predicate); - assertEquals(expected, segment); - } -} diff --git a/src/test/java/com/tempodb/json/DataPointFoundTest.java b/src/test/java/com/tempodb/json/DataPointFoundTest.java deleted file mode 100644 index e4d1317..0000000 --- a/src/test/java/com/tempodb/json/DataPointFoundTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.DataPoint; -import com.tempodb.DataPointFound; - - -public class DataPointFoundTest { - - @Test - public void testDeserializeUTC() throws IOException { - String json = "{\"interval\":{\"start\":\"2012-03-28T00:00:00.000Z\",\"end\":\"2012-03-29T00:00:00.000Z\"},\"found\":{\"t\":\"2012-03-28T23:59:00.000Z\",\"v\":2879.0}}"; - DateTimeZone zone = DateTimeZone.UTC; - DataPointFound found = Json.loads(json, DataPointFound.class, zone); - Interval interval = new Interval(new DateTime(2012, 3, 28, 0, 0, 0, 0, zone), new DateTime(2012, 3, 29, 0, 0, 0, 0, zone)); - DataPoint datapoint = new DataPoint(new DateTime(2012, 3, 28, 23, 59, 0, 0, zone), 2879.0); - DataPointFound expected = new DataPointFound(interval, datapoint); - assertEquals(expected, found); - } - - @Test - public void testDeserializeTZ() throws IOException { - String json = "{\"interval\":{\"start\":\"2012-03-28T00:00:00.000Z\",\"end\":\"2012-03-29T00:00:00.000Z\"},\"found\":{\"t\":\"2012-03-28T23:59:00.000Z\",\"v\":2879.0}}"; - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - DataPointFound found = Json.loads(json, DataPointFound.class, zone); - Interval interval = new Interval(new DateTime(2012, 3, 27, 19, 0, 0, 0, zone), new DateTime(2012, 3, 28, 19, 0, 0, 0, zone)); - DataPoint datapoint = new DataPoint(new DateTime(2012, 3, 28, 18, 59, 0, 0, zone), 2879.0); - DataPointFound expected = new DataPointFound(interval, datapoint); - assertEquals(expected, found); - } -} diff --git a/src/test/java/com/tempodb/json/DataPointSegmentTest.java b/src/test/java/com/tempodb/json/DataPointSegmentTest.java deleted file mode 100644 index 02ef76c..0000000 --- a/src/test/java/com/tempodb/json/DataPointSegmentTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.DataPoint; -import com.tempodb.DataPointSegment; -import com.tempodb.Rollup; -import com.tempodb.Fold; - - -public class DataPointSegmentTest { - - @Test - public void testDeserializeUTC() throws IOException { - String json = "{" + - "\"rollup\":{" + - "\"fold\":\"sum\"," + - "\"period\":\"PT1H\"" + - "}," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:01.000Z\",\"v\":12.34}" + - "]" + - "}"; - - DateTimeZone zone = DateTimeZone.UTC; - DataPointSegment segment = Json.loads(json, DataPointSegment.class); - - List data = Arrays.asList(new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, 0, zone), 12.34)); - Rollup rollup = new Rollup(Period.hours(1), Fold.SUM); - DataPointSegment expected = new DataPointSegment(data, null, zone, rollup); - assertEquals(expected, segment); - } - - @Test - public void testDeserializeTZ() throws IOException { - String json = "{" + - "\"rollup\":{" + - "\"fold\":\"sum\"," + - "\"period\":\"PT1H\"" + - "}," + - "\"tz\":\"America/Chicago\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:01.000-06:00\",\"v\":12.34}" + - "]" + - "}"; - - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - DataPointSegment segment = Json.loads(json, DataPointSegment.class); - - List data = Arrays.asList(new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, 0, zone), 12.34)); - Rollup rollup = new Rollup(Period.hours(1), Fold.SUM); - DataPointSegment expected = new DataPointSegment(data, null, zone, rollup); - assertEquals(expected, segment); - } - - @Test - public void testDeserializeRollupNull() throws IOException { - String json = "{" + - "\"rollup\":null," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:01.000Z\",\"v\":12.34}" + - "]" + - "}"; - - DateTimeZone zone = DateTimeZone.forID("UTC"); - DataPointSegment segment = Json.loads(json, DataPointSegment.class); - - List data = Arrays.asList(new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, 0, zone), 12.34)); - Rollup rollup = null; - DataPointSegment expected = new DataPointSegment(data, null, zone, rollup); - assertEquals(expected, segment); - } -} diff --git a/src/test/java/com/tempodb/json/DataPointTest.java b/src/test/java/com/tempodb/json/DataPointTest.java deleted file mode 100644 index 4e65b21..0000000 --- a/src/test/java/com/tempodb/json/DataPointTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.DataPoint; - - -public class DataPointTest { - - @Test - public void testDeserializeUTC() throws IOException { - DateTimeZone zone = DateTimeZone.UTC; - DataPoint datapoint = Json.loads("{\"t\":\"2012-01-01T00:00:01.000Z\",\"v\":12.34}", DataPoint.class, zone); - DataPoint expected = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, 0, zone), 12.34); - assertEquals(expected, datapoint); - } - - @Test - public void testDeserializeTZ() throws IOException { - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - DataPoint datapoint = Json.loads("{\"t\":\"2012-01-01T00:00:01.000-06:00\",\"v\":12.34}", DataPoint.class, zone); - DataPoint expected = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, 0, zone), 12.34); - assertEquals(expected, datapoint); - } - - @Test - public void testSerializeUTC() throws IOException { - DateTimeZone zone = DateTimeZone.UTC; - DataPoint datapoint = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, 0, zone), 12.34); - - String expected = "{\"t\":\"2012-01-01T00:00:01.000Z\",\"v\":12.34}"; - assertEquals(expected, Json.dumps(datapoint)); - } - - @Test - public void testSerializeTZ() throws IOException { - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - DataPoint datapoint = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, 0, zone), 12.34); - - String expected = "{\"t\":\"2012-01-01T00:00:01.000-06:00\",\"v\":12.34}"; - assertEquals(expected, Json.dumps(datapoint)); - } -} diff --git a/src/test/java/com/tempodb/json/DeleteSummaryTest.java b/src/test/java/com/tempodb/json/DeleteSummaryTest.java deleted file mode 100644 index 9ab81d7..0000000 --- a/src/test/java/com/tempodb/json/DeleteSummaryTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; - -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.DeleteSummary; - - -public class DeleteSummaryTest { - - @Test - public void testDeserialize() throws IOException { - String json = "{\"deleted\":1}"; - DeleteSummary expected = new DeleteSummary(1); - assertEquals(expected, Json.loads(json, DeleteSummary.class)); - } - - @Test - public void testSerialize() throws IOException { - DeleteSummary summary = new DeleteSummary(2); - String expected = "{\"deleted\":2}"; - assertEquals(expected, Json.dumps(summary)); - } -} diff --git a/src/test/java/com/tempodb/json/MultiDataPointSegmentTest.java b/src/test/java/com/tempodb/json/MultiDataPointSegmentTest.java deleted file mode 100644 index 15f07f1..0000000 --- a/src/test/java/com/tempodb/json/MultiDataPointSegmentTest.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.Fold; -import com.tempodb.MultiDataPoint; -import com.tempodb.MultiDataPointSegment; -import com.tempodb.Rollup; - - -public class MultiDataPointSegmentTest { - - private static final Map data1; - private static final Map data2; - private static final Map data3; - - static { - data1 = new HashMap(); - data1.put("key1", 12.34); - data1.put("key2", 23.45); - - data2 = new HashMap(); - data2.put("key1", 23.45); - data2.put("key2", 34.56); - - data3 = new HashMap(); - data3.put("key1", 34.56); - data3.put("key2", 45.67); - } - - @Test - public void testDeserializeUTC() throws IOException { - String json = "{" + - "\"rollup\":{" + - "\"fold\":\"sum\"," + - "\"period\":\"PT1H\"" + - "}," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:00.000Z\",\"v\":{\"key1\":12.34,\"key2\":23.45}}," + - "{\"t\":\"2012-01-01T01:00:00.000Z\",\"v\":{\"key1\":23.45,\"key2\":34.56}}," + - "{\"t\":\"2012-01-01T02:00:00.000Z\",\"v\":{\"key1\":34.56,\"key2\":45.67}}" + - "]" + - "}"; - - DateTimeZone zone = DateTimeZone.UTC; - MultiDataPointSegment segment = Json.loads(json, MultiDataPointSegment.class); - - List data = Arrays.asList( - new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, zone), data1), - new MultiDataPoint(new DateTime(2012, 1, 1, 1, 0, 0, 0, zone), data2), - new MultiDataPoint(new DateTime(2012, 1, 1, 2, 0, 0, 0, zone), data3) - ); - Rollup rollup = new Rollup(Period.hours(1), Fold.SUM); - MultiDataPointSegment expected = new MultiDataPointSegment(data, null, zone, rollup); - assertEquals(expected, segment); - } - - @Test - public void testDeserializeTZ() throws IOException { - String json = "{" + - "\"rollup\":{" + - "\"fold\":\"sum\"," + - "\"period\":\"PT1H\"" + - "}," + - "\"tz\":\"America/Chicago\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:00.000-06:00\",\"v\":{\"key1\":12.34,\"key2\":23.45}}," + - "{\"t\":\"2012-01-01T01:00:00.000-06:00\",\"v\":{\"key1\":23.45,\"key2\":34.56}}," + - "{\"t\":\"2012-01-01T02:00:00.000-06:00\",\"v\":{\"key1\":34.56,\"key2\":45.67}}" + - "]" + - "}"; - - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - MultiDataPointSegment segment = Json.loads(json, MultiDataPointSegment.class); - - List data = Arrays.asList( - new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, zone), data1), - new MultiDataPoint(new DateTime(2012, 1, 1, 1, 0, 0, 0, zone), data2), - new MultiDataPoint(new DateTime(2012, 1, 1, 2, 0, 0, 0, zone), data3) - ); - Rollup rollup = new Rollup(Period.hours(1), Fold.SUM); - MultiDataPointSegment expected = new MultiDataPointSegment(data, null, zone, rollup); - assertEquals(expected, segment); - } - - @Test - public void testDeserializeRollupNull() throws IOException { - String json = "{" + - "\"rollup\":null," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:00.000Z\",\"v\":{\"key1\":12.34,\"key2\":23.45}}," + - "{\"t\":\"2012-01-01T01:00:00.000Z\",\"v\":{\"key1\":23.45,\"key2\":34.56}}," + - "{\"t\":\"2012-01-01T02:00:00.000Z\",\"v\":{\"key1\":34.56,\"key2\":45.67}}" + - "]" + - "}"; - - DateTimeZone zone = DateTimeZone.forID("UTC"); - MultiDataPointSegment segment = Json.loads(json, MultiDataPointSegment.class); - - List data = Arrays.asList( - new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, zone), data1), - new MultiDataPoint(new DateTime(2012, 1, 1, 1, 0, 0, 0, zone), data2), - new MultiDataPoint(new DateTime(2012, 1, 1, 2, 0, 0, 0, zone), data3) - ); - Rollup rollup = null; - MultiDataPointSegment expected = new MultiDataPointSegment(data, null, zone, rollup); - assertEquals(expected, segment); - } -} diff --git a/src/test/java/com/tempodb/json/MultiDataPointTest.java b/src/test/java/com/tempodb/json/MultiDataPointTest.java deleted file mode 100644 index 5fe21c6..0000000 --- a/src/test/java/com/tempodb/json/MultiDataPointTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.MultiDataPoint; - - -public class MultiDataPointTest { - - private static Map data; - static { - data = new HashMap(); - data.put("key1", 12.34); - data.put("key2", 23.45); - } - - @Test - public void testDeserializeUTC() throws IOException { - String json = "{\"t\":\"2012-01-01T00:00:00.000Z\",\"v\":{\"key2\":23.45,\"key1\":12.34}}"; - DateTimeZone zone = DateTimeZone.UTC; - MultiDataPoint datapoint = Json.loads(json, MultiDataPoint.class, zone); - - MultiDataPoint expected = new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, zone), data); - assertEquals(expected, datapoint); - } - - @Test - public void testDeserializeTZ() throws IOException { - String json = "{\"t\":\"2012-01-01T00:00:00.000-06:00\",\"v\":{\"key2\":23.45,\"key1\":12.34}}"; - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - MultiDataPoint datapoint = Json.loads(json, MultiDataPoint.class, zone); - MultiDataPoint expected = new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, zone), data); - assertEquals(expected, datapoint); - } -} diff --git a/src/test/java/com/tempodb/json/MultiRollupDataPointSegmentTest.java b/src/test/java/com/tempodb/json/MultiRollupDataPointSegmentTest.java deleted file mode 100644 index 055d50e..0000000 --- a/src/test/java/com/tempodb/json/MultiRollupDataPointSegmentTest.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.Fold; -import com.tempodb.MultiDataPoint; -import com.tempodb.MultiRollup; -import com.tempodb.MultiRollupDataPointSegment; - - -public class MultiRollupDataPointSegmentTest { - - private static final Map data1; - private static final Map data2; - private static final Map data3; - - static { - data1 = new HashMap(); - data1.put("sum", 12.34); - data1.put("max", 23.45); - - data2 = new HashMap(); - data2.put("sum", 23.45); - data2.put("max", 34.56); - - data3 = new HashMap(); - data3.put("sum", 34.56); - data3.put("max", 45.67); - } - - @Test - public void testDeserializeUTC() throws IOException { - String json = "{" + - "\"rollup\":{" + - "\"folds\":[\"sum\",\"max\"]," + - "\"period\":\"PT1H\"" + - "}," + - "\"tz\":\"UTC\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:00.000Z\",\"v\":{\"sum\":12.34,\"max\":23.45}}," + - "{\"t\":\"2012-01-01T01:00:00.000Z\",\"v\":{\"sum\":23.45,\"max\":34.56}}," + - "{\"t\":\"2012-01-01T02:00:00.000Z\",\"v\":{\"sum\":34.56,\"max\":45.67}}" + - "]" + - "}"; - - DateTimeZone zone = DateTimeZone.UTC; - MultiRollupDataPointSegment segment = Json.loads(json, MultiRollupDataPointSegment.class); - - List data = Arrays.asList( - new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, zone), data1), - new MultiDataPoint(new DateTime(2012, 1, 1, 1, 0, 0, 0, zone), data2), - new MultiDataPoint(new DateTime(2012, 1, 1, 2, 0, 0, 0, zone), data3) - ); - MultiRollup rollup = new MultiRollup(Period.hours(1), new Fold[] { Fold.SUM, Fold.MAX }); - MultiRollupDataPointSegment expected = new MultiRollupDataPointSegment(data, null, zone, rollup); - assertEquals(expected, segment); - } - - @Test - public void testDeserializeTZ() throws IOException { - String json = "{" + - "\"rollup\":{" + - "\"folds\":[\"sum\",\"max\"]," + - "\"period\":\"PT1H\"" + - "}," + - "\"tz\":\"America/Chicago\"," + - "\"data\":[" + - "{\"t\":\"2012-01-01T00:00:00.000-06:00\",\"v\":{\"sum\":12.34,\"max\":23.45}}," + - "{\"t\":\"2012-01-01T01:00:00.000-06:00\",\"v\":{\"sum\":23.45,\"max\":34.56}}," + - "{\"t\":\"2012-01-01T02:00:00.000-06:00\",\"v\":{\"sum\":34.56,\"max\":45.67}}" + - "]" + - "}"; - - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - MultiRollupDataPointSegment segment = Json.loads(json, MultiRollupDataPointSegment.class); - - List data = Arrays.asList( - new MultiDataPoint(new DateTime(2012, 1, 1, 0, 0, 0, 0, zone), data1), - new MultiDataPoint(new DateTime(2012, 1, 1, 1, 0, 0, 0, zone), data2), - new MultiDataPoint(new DateTime(2012, 1, 1, 2, 0, 0, 0, zone), data3) - ); - MultiRollup rollup = new MultiRollup(Period.hours(1), new Fold[] { Fold.SUM, Fold.MAX }); - MultiRollupDataPointSegment expected = new MultiRollupDataPointSegment(data, null, zone, rollup); - assertEquals(expected, segment); - } -} diff --git a/src/test/java/com/tempodb/json/MultiRollupTest.java b/src/test/java/com/tempodb/json/MultiRollupTest.java deleted file mode 100644 index ffc6c6b..0000000 --- a/src/test/java/com/tempodb/json/MultiRollupTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; - -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.Fold; -import com.tempodb.MultiRollup; - - -public class MultiRollupTest { - - @Test - public void testDeserialize() throws IOException { - String json = "{" + - "\"period\":\"PT1M\"," + - "\"folds\":[\"max\",\"sum\"]" + - "}"; - - MultiRollup rollup = Json.loads(json, MultiRollup.class); - MultiRollup expected = new MultiRollup(Period.minutes(1), new Fold[] { Fold.MAX, Fold.SUM }); - assertEquals(expected, rollup); - } - - @Test - public void testSerialize() throws IOException { - MultiRollup rollup = new MultiRollup(Period.minutes(1), new Fold[] { Fold.MAX, Fold.SUM }); - String expected = "{" + - "\"period\":\"PT1M\"," + - "\"folds\":[\"max\",\"sum\"]" + - "}"; - assertEquals(expected, Json.dumps(rollup)); - } -} diff --git a/src/test/java/com/tempodb/json/MultiStatusTest.java b/src/test/java/com/tempodb/json/MultiStatusTest.java deleted file mode 100644 index dcd784d..0000000 --- a/src/test/java/com/tempodb/json/MultiStatusTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.Arrays; - -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.MultiStatus; -import com.tempodb.Status; - - -public class MultiStatusTest { - - @Test - public void testDeserialize() throws IOException { - String json = "{\"multistatus\":[{\"status\":1,\"messages\":[\"message1\"]}]}"; - MultiStatus expected = new MultiStatus(Arrays.asList(new Status(1, Arrays.asList("message1")))); - assertEquals(expected, Json.loads(json, MultiStatus.class)); - } - - @Test - public void testSerialize() throws IOException { - MultiStatus multistatus = new MultiStatus(Arrays.asList(new Status(200, Arrays.asList("message1", "message2")))); - String expected = "{\"multistatus\":[{\"status\":200,\"messages\":[\"message1\",\"message2\"]}]}"; - assertEquals(expected, Json.dumps(multistatus)); - } -} diff --git a/src/test/java/com/tempodb/json/PredicateTest.java b/src/test/java/com/tempodb/json/PredicateTest.java deleted file mode 100644 index 9a9a1f4..0000000 --- a/src/test/java/com/tempodb/json/PredicateTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; - -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.Predicate; - - -public class PredicateTest { - - @Test - public void testDeserialize() throws IOException { - Predicate rollup = Json.loads("{\"period\":\"PT1M\",\"function\":\"max\"}", Predicate.class); - Predicate expected = new Predicate(Period.minutes(1), "max"); - assertEquals(expected, rollup); - } - - @Test - public void testSerialize() throws IOException { - Predicate rollup = new Predicate(Period.minutes(1), "max"); - String expected = "{\"period\":\"PT1M\",\"function\":\"max\"}"; - assertEquals(expected, Json.dumps(rollup)); - } -} diff --git a/src/test/java/com/tempodb/json/RollupTest.java b/src/test/java/com/tempodb/json/RollupTest.java deleted file mode 100644 index eefd078..0000000 --- a/src/test/java/com/tempodb/json/RollupTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; - -import org.joda.time.Period; -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.Fold; -import com.tempodb.Rollup; - - -public class RollupTest { - - @Test - public void testDeserialize() throws IOException { - Rollup rollup = Json.loads("{\"period\":\"PT1M\",\"fold\":\"sum\"}", Rollup.class); - Rollup expected = new Rollup(Period.minutes(1), Fold.SUM); - assertEquals(expected, rollup); - } - - @Test - public void testSerialize() throws IOException { - Rollup rollup = new Rollup(Period.minutes(1), Fold.SUM); - String expected = "{\"period\":\"PT1M\",\"fold\":\"sum\"}"; - assertEquals(expected, Json.dumps(rollup)); - } -} diff --git a/src/test/java/com/tempodb/json/SeriesSegmentTest.java b/src/test/java/com/tempodb/json/SeriesSegmentTest.java deleted file mode 100644 index e9314b4..0000000 --- a/src/test/java/com/tempodb/json/SeriesSegmentTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.Series; -import com.tempodb.SeriesSegment; - - -public class SeriesSegmentTest { - - private static final Set tags = new LinkedHashSet(Arrays.asList("tag1", "tag2")); - private static final Map attributes; - static { - Map map = new HashMap(); - map.put("key1", "value1"); - attributes = Collections.unmodifiableMap(map); - } - - @Test - public void testDeserialize() throws IOException { - String json = "[" + - "{\"id\":\"id1\",\"key\":\"key1\",\"name\":\"name1\",\"tags\":[\"tag1\",\"tag2\"],\"attributes\":{\"key1\":\"value1\"}}" + - "]"; - - SeriesSegment segment = Json.loads(json, SeriesSegment.class); - List data = Arrays.asList(new Series("key1", "name1", tags, attributes)); - SeriesSegment expected = new SeriesSegment(data, null); - assertEquals(expected, segment); - } -} diff --git a/src/test/java/com/tempodb/json/SeriesTest.java b/src/test/java/com/tempodb/json/SeriesTest.java deleted file mode 100644 index 0c8f890..0000000 --- a/src/test/java/com/tempodb/json/SeriesTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; - -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.Series; - - -public class SeriesTest { - - private static final Set tags = new LinkedHashSet(Arrays.asList("tag1", "tag2")); - private static final Map attributes; - static { - Map map = new HashMap(); - map.put("key1", "value1"); - attributes = Collections.unmodifiableMap(map); - } - - private static final Series series = new Series("key1", "name1", tags, attributes); - - @Test - public void testDeserialize() throws IOException { - String json = "{\"id\":\"id1\",\"key\":\"key1\",\"name\":\"name1\",\"tags\":[\"tag1\",\"tag2\"],\"attributes\":{\"key1\":\"value1\"}}"; - Series deserialized = Json.loads(json, Series.class); - assertEquals(series, deserialized); - } - - @Test - public void testSerialize() throws IOException { - String expected = "{\"key\":\"key1\",\"name\":\"name1\",\"tags\":[\"tag1\",\"tag2\"],\"attributes\":{\"key1\":\"value1\"}}"; - String json = Json.dumps(series); - assertEquals(expected, json); - } -} diff --git a/src/test/java/com/tempodb/json/SingleValueSegmentTest.java b/src/test/java/com/tempodb/json/SingleValueSegmentTest.java deleted file mode 100644 index d1efe97..0000000 --- a/src/test/java/com/tempodb/json/SingleValueSegmentTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.DataPoint; -import com.tempodb.Series; -import com.tempodb.SingleValue; -import com.tempodb.SingleValueSegment; - - -public class SingleValueSegmentTest { - - private static final Set tags = new LinkedHashSet(Arrays.asList("tag1", "tag2")); - private static final Map attributes; - static { - Map map = new HashMap(); - map.put("key1", "value1"); - attributes = Collections.unmodifiableMap(map); - } - - @Test - public void testDeserialize() throws IOException { - String json = "[{" + - "\"series\":{" + - "\"id\":\"id1\"," + - "\"key\":\"key1\"," + - "\"name\":\"name1\"," + - "\"tags\":[\"tag1\",\"tag2\"]," + - "\"attributes\":{\"key1\":\"value1\"}" + - "}," + - "\"data\":{" + - "\"t\":\"2012-01-01T00:00:01.000Z\"," + - "\"v\":12.34" + - "}," + - "\"tz\":\"UTC\"" + - "}]"; - - DateTimeZone zone = DateTimeZone.UTC; - SingleValueSegment segment = Json.loads(json, SingleValueSegment.class); - - Series series = new Series("key1", "name1", tags, attributes); - DataPoint datapoint = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, 0, zone), 12.34); - List data = Arrays.asList(new SingleValue(series, datapoint)); - SingleValueSegment expected = new SingleValueSegment(data); - assertEquals(expected, segment); - } -} diff --git a/src/test/java/com/tempodb/json/SingleValueTest.java b/src/test/java/com/tempodb/json/SingleValueTest.java deleted file mode 100644 index 6205fcd..0000000 --- a/src/test/java/com/tempodb/json/SingleValueTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.DataPoint; -import com.tempodb.Series; -import com.tempodb.SingleValue; - - -public class SingleValueTest { - - private static final Series series = new Series("key1"); - - @Test - public void testDeserializeUTC() throws IOException { - String json = "{" + - "\"series\":{" + - "\"id\":\"id1\"," + - "\"key\":\"key1\"," + - "\"name\":\"\"," + - "\"tags\":[]," + - "\"attributes\":{}" + - "}," + - "\"data\":{" + - "\"t\":\"2012-01-01T00:00:01.000Z\"," + - "\"v\":12.34" + - "}," + - "\"tz\":\"UTC\"" + - "}"; - - DateTimeZone zone = DateTimeZone.UTC; - SingleValue value = Json.loads(json, SingleValue.class); - - DataPoint datapoint = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, 0, zone), 12.34); - SingleValue expected = new SingleValue(series, datapoint); - assertEquals(expected, value); - } - - @Test - public void testDeserializeTZ() throws IOException { - String json = "{" + - "\"series\":{" + - "\"id\":\"id1\"," + - "\"key\":\"key1\"," + - "\"name\":\"\"," + - "\"tags\":[]," + - "\"attributes\":{}" + - "}," + - "\"data\":{" + - "\"t\":\"2012-01-01T00:00:01.000-06:00\"," + - "\"v\":12.34" + - "}," + - "\"tz\":\"America/Chicago\"" + - "}"; - - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - SingleValue value = Json.loads(json, SingleValue.class); - - DataPoint datapoint = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, 0, zone), 12.34); - SingleValue expected = new SingleValue(series, datapoint); - assertEquals(expected, value); - } -} diff --git a/src/test/java/com/tempodb/json/StatusTest.java b/src/test/java/com/tempodb/json/StatusTest.java deleted file mode 100644 index 57779f7..0000000 --- a/src/test/java/com/tempodb/json/StatusTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; - -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.Status; - - -public class StatusTest { - - @Test - public void testDeserialize() throws IOException { - String json = "{\"status\":1,\"messages\":[\"message1\"]}"; - Status expected = new Status(1, Arrays.asList("message1")); - assertEquals(expected, Json.loads(json, Status.class)); - } - - @Test - public void testDeserialize_EmptyMessages() throws IOException { - String json = "{\"status\":1,\"messages\":[]}"; - Status expected = new Status(1, new ArrayList()); - assertEquals(expected, Json.loads(json, Status.class)); - } - - @Test - public void testSerialize() throws IOException { - Status status = new Status(200, Arrays.asList("message1", "message2")); - String expected = "{\"status\":200,\"messages\":[\"message1\",\"message2\"]}"; - assertEquals(expected, Json.dumps(status)); - } -} diff --git a/src/test/java/com/tempodb/json/SummaryTest.java b/src/test/java/com/tempodb/json/SummaryTest.java deleted file mode 100644 index c8c10bb..0000000 --- a/src/test/java/com/tempodb/json/SummaryTest.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.Interval; -import org.junit.*; -import static org.junit.Assert.*; - -import com.tempodb.Series; -import com.tempodb.Summary; - - -public class SummaryTest { - - @Test - public void testDeserialize() throws IOException { - String json = "{" + - "\"summary\":{" + - "\"max\":12.34," + - "\"min\":23.45" + - "}," + - "\"tz\":\"UTC\"," + - "\"start\":\"2012-01-01T00:00:00.000Z\"," + - "\"end\":\"2012-01-02T00:00:00.000Z\"," + - "\"series\":{" + - "\"id\":\"id1\"," + - "\"key\":\"key1\"," + - "\"name\":\"\"," + - "\"tags\":[]," + - "\"attributes\":{}" + - "}" + - "}"; - - DateTimeZone zone = DateTimeZone.UTC; - DateTime start = new DateTime(2012, 1, 1, 0, 0, 0, 0, zone); - DateTime end = new DateTime(2012, 1, 2, 0, 0, 0, 0, zone); - - Map data = new HashMap(); - data.put("max", 12.34); - data.put("min", 23.45); - - Series series = new Series("key1"); - - Summary summary = Json.loads(json, Summary.class); - Summary expected = new Summary(series, new Interval(start, end), data); - assertEquals(expected, summary); - } - - @Test - public void testDeserializeTz() throws IOException { - String json = "{" + - "\"summary\":{" + - "\"max\":12.34," + - "\"min\":23.45" + - "}," + - "\"tz\":\"America/Chicago\"," + - "\"start\":\"2012-01-01T00:00:00.000-06:00\"," + - "\"end\":\"2012-01-02T00:00:00.000-06:00\"," + - "\"series\":{" + - "\"id\":\"id1\"," + - "\"key\":\"key1\"," + - "\"name\":\"\"," + - "\"tags\":[]," + - "\"attributes\":{}" + - "}" + - "}"; - - DateTimeZone zone = DateTimeZone.forID("America/Chicago"); - DateTime start = new DateTime(2012, 1, 1, 0, 0, 0, 0, zone); - DateTime end = new DateTime(2012, 1, 2, 0, 0, 0, 0, zone); - - Map data = new HashMap(); - data.put("max", 12.34); - data.put("min", 23.45); - - Series series = new Series("key1"); - - Summary summary = Json.loads(json, Summary.class); - Summary expected = new Summary(series, new Interval(start, end), data); - assertEquals(expected, summary); - } -} diff --git a/src/test/java/com/tempodb/json/WritableDataPointTest.java b/src/test/java/com/tempodb/json/WritableDataPointTest.java deleted file mode 100644 index 37389ed..0000000 --- a/src/test/java/com/tempodb/json/WritableDataPointTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; - -import com.fasterxml.jackson.databind.JsonMappingException; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.junit.*; -import static org.junit.Assert.*; -import org.junit.rules.ExpectedException; - -import com.tempodb.WritableDataPoint; -import com.tempodb.Series; - - -public class WritableDataPointTest { - private static final DateTimeZone timezone = DateTimeZone.UTC; - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void testSerialize() throws IOException { - DateTimeZone zone = DateTimeZone.UTC; - WritableDataPoint datapoint = new WritableDataPoint(new Series("key1"),new DateTime(2012, 1, 1, 0, 0, 1, 0, timezone), 12.34); - - String expected = "{\"key\":\"key1\",\"t\":\"2012-01-01T00:00:01.000Z\",\"v\":12.34}"; - assertEquals(expected, Json.dumps(datapoint)); - } -} diff --git a/src/test/java/com/tempodb/json/WriteRequestTest.java b/src/test/java/com/tempodb/json/WriteRequestTest.java deleted file mode 100644 index df9373d..0000000 --- a/src/test/java/com/tempodb/json/WriteRequestTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.tempodb.json; - -import java.io.IOException; - -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.junit.*; -import static org.junit.Assert.*; -import org.junit.rules.ExpectedException; - -import com.tempodb.DataPoint; -import com.tempodb.Series; -import com.tempodb.WriteRequest; - - -public class WriteRequestTest { - private static final Series series = new Series("key1"); - - @Test - public void testSerializeUTC() throws IOException { - DateTimeZone timezone = DateTimeZone.UTC; - DataPoint dp = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, 0, timezone), 12.34); - WriteRequest wr = new WriteRequest().add(series, dp); - - String expected = "[{\"key\":\"key1\",\"t\":\"2012-01-01T00:00:01.000Z\",\"v\":12.34}]"; - assertEquals(expected, Json.dumps(wr)); - } - - @Test - public void testSerializeTZ() throws IOException { - DateTimeZone timezone = DateTimeZone.forID("America/Chicago"); - DataPoint dp = new DataPoint(new DateTime(2012, 1, 1, 0, 0, 1, 0, timezone), 12.34); - WriteRequest wr = new WriteRequest().add(series, dp); - - String expected = "[{\"key\":\"key1\",\"t\":\"2012-01-01T00:00:01.000-06:00\",\"v\":12.34}]"; - assertEquals(expected, Json.dumps(wr)); - } -}