http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/test/java/org/apache/calcite/avatica/test/JsonHandlerTest.java ---------------------------------------------------------------------- diff --git a/avatica/core/src/test/java/org/apache/calcite/avatica/test/JsonHandlerTest.java b/avatica/core/src/test/java/org/apache/calcite/avatica/test/JsonHandlerTest.java deleted file mode 100644 index 7afa000..0000000 --- a/avatica/core/src/test/java/org/apache/calcite/avatica/test/JsonHandlerTest.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.test; - -import org.apache.calcite.avatica.AvaticaParameter; -import org.apache.calcite.avatica.ColumnMetaData; -import org.apache.calcite.avatica.Meta; -import org.apache.calcite.avatica.Meta.CursorFactory; -import org.apache.calcite.avatica.metrics.noop.NoopMetricsSystem; -import org.apache.calcite.avatica.remote.JsonHandler; -import org.apache.calcite.avatica.remote.JsonService; -import org.apache.calcite.avatica.remote.LocalJsonService; -import org.apache.calcite.avatica.remote.Service; -import org.apache.calcite.avatica.remote.TypedValue; - -import org.junit.Test; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Random; -import java.util.UUID; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -/** - * Tests JSON encoding/decoding in the remote service. - */ -public class JsonHandlerTest { - - private static final Random RANDOM = new Random(); - - /** - * Implementation of {@link org.apache.calcite.avatica.remote.Service} - * that does nothing. - */ - public static class NoopService implements Service { - @Override public ResultSetResponse apply(CatalogsRequest request) { - return null; - } - - @Override public ResultSetResponse apply(SchemasRequest request) { - return null; - } - - @Override public ResultSetResponse apply(TablesRequest request) { - return null; - } - - @Override public ResultSetResponse apply(TableTypesRequest request) { - return null; - } - - @Override public ResultSetResponse apply(TypeInfoRequest request) { - return null; - } - - @Override public ResultSetResponse apply(ColumnsRequest request) { - return null; - } - - @Override public PrepareResponse apply(PrepareRequest request) { - return null; - } - - @Override public ExecuteResponse apply(PrepareAndExecuteRequest request) { - return null; - } - - @Override public FetchResponse apply(FetchRequest request) { - return null; - } - - @Override public CreateStatementResponse apply(CreateStatementRequest request) { - return null; - } - - @Override public CloseStatementResponse apply(CloseStatementRequest request) { - return null; - } - - @Override public OpenConnectionResponse apply(OpenConnectionRequest request) { - return null; - } - - @Override public CloseConnectionResponse apply(CloseConnectionRequest request) { - return null; - } - - @Override public ConnectionSyncResponse apply(ConnectionSyncRequest request) { - return null; - } - - @Override public DatabasePropertyResponse apply(DatabasePropertyRequest request) { - return null; - } - - @Override public SyncResultsResponse apply(SyncResultsRequest request) { - return null; - } - - @Override public ExecuteResponse apply(ExecuteRequest request) { - return null; - } - - @Override public void setRpcMetadata(RpcMetadataResponse metadata) {} - - @Override public CommitResponse apply(CommitRequest request) { - return null; - } - - @Override public RollbackResponse apply(RollbackRequest request) { - return null; - } - - @Override public ExecuteBatchResponse apply(ExecuteBatchRequest request) { - return null; - } - - @Override public ExecuteBatchResponse apply(PrepareAndExecuteBatchRequest request) { - return null; - } - } - - /** - * Instrumented subclass of {@link org.apache.calcite.avatica.test.JsonHandlerTest.NoopService} - * that checks the parameter values passed to the "execute" request. - * - * <p>Note: parameter values for "fetch" request deprecated. - */ - public static class ParameterValuesCheckingService extends NoopService { - - final List<TypedValue> expectedParameterValues; - - public ParameterValuesCheckingService(List<TypedValue> epv) { - expectedParameterValues = epv; - } - - @Override public ExecuteResponse apply(ExecuteRequest request) { - expectedParameterValues.addAll(request.parameterValues); - - final Meta.Signature signature = - new Meta.Signature(Collections.<ColumnMetaData>emptyList(), - "SELECT 1 FROM VALUE()", - Collections.<AvaticaParameter>emptyList(), - Collections.<String, Object>emptyMap(), - CursorFactory.LIST, Meta.StatementType.SELECT); - - final Service.ResultSetResponse resultSetResponse = - new Service.ResultSetResponse(UUID.randomUUID().toString(), - RANDOM.nextInt(), false, signature, Meta.Frame.EMPTY, -1L, null); - - return new Service.ExecuteResponse( - Collections.singletonList(resultSetResponse), false, null); - } - } - - @Test public void testExecuteRequestWithNumberParameter() { - final List<TypedValue> expectedParameterValues = new ArrayList<>(); - final Service service = new ParameterValuesCheckingService(expectedParameterValues); - final JsonService jsonService = new LocalJsonService(service); - final JsonHandler jsonHandler = new JsonHandler(jsonService, NoopMetricsSystem.getInstance()); - - final List<TypedValue> parameterValues = Arrays.asList( - TypedValue.create("NUMBER", new BigDecimal("123")), - TypedValue.create("STRING", "calcite")); - - jsonHandler.apply( - "{'request':'execute'," - + "'parameterValues':[{'type':'NUMBER','value':123}," - + "{'type':'STRING','value':'calcite'}]}"); - assertThat(expectedParameterValues.size(), is(2)); - assertThat(expectedParameterValues.get(0), is(parameterValues.get(0))); - assertThat(expectedParameterValues.get(1), is(parameterValues.get(1))); - } -} - -// End JsonHandlerTest.java
http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/test/java/org/apache/calcite/avatica/test/package-info.java ---------------------------------------------------------------------- diff --git a/avatica/core/src/test/java/org/apache/calcite/avatica/test/package-info.java b/avatica/core/src/test/java/org/apache/calcite/avatica/test/package-info.java deleted file mode 100644 index 501bb9f..0000000 --- a/avatica/core/src/test/java/org/apache/calcite/avatica/test/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Avatica tests. - */ -@PackageMarker -package org.apache.calcite.avatica.test; - -import org.apache.calcite.avatica.util.PackageMarker; - -// End package-info.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java ---------------------------------------------------------------------- diff --git a/avatica/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java b/avatica/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java deleted file mode 100644 index 1ac1a90..0000000 --- a/avatica/core/src/test/java/org/apache/calcite/avatica/util/DateTimeUtilsTest.java +++ /dev/null @@ -1,526 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.util; - -import org.junit.Test; - -import static org.apache.calcite.avatica.util.DateTimeUtils.EPOCH_JULIAN; -import static org.apache.calcite.avatica.util.DateTimeUtils.addMonths; -import static org.apache.calcite.avatica.util.DateTimeUtils.dateStringToUnixDate; - - -import static org.apache.calcite.avatica.util.DateTimeUtils.digitCount; -import static org.apache.calcite.avatica.util.DateTimeUtils.floorDiv; -import static org.apache.calcite.avatica.util.DateTimeUtils.floorMod; -import static org.apache.calcite.avatica.util.DateTimeUtils.intervalDayTimeToString; -import static org.apache.calcite.avatica.util.DateTimeUtils.intervalYearMonthToString; -import static org.apache.calcite.avatica.util.DateTimeUtils.subtractMonths; -import static org.apache.calcite.avatica.util.DateTimeUtils.timeStringToUnixDate; -import static org.apache.calcite.avatica.util.DateTimeUtils.timestampStringToUnixDate; -import static org.apache.calcite.avatica.util.DateTimeUtils.unixDateExtract; -import static org.apache.calcite.avatica.util.DateTimeUtils.unixDateToString; -import static org.apache.calcite.avatica.util.DateTimeUtils.unixTimeExtract; -import static org.apache.calcite.avatica.util.DateTimeUtils.unixTimeToString; -import static org.apache.calcite.avatica.util.DateTimeUtils.unixTimestamp; -import static org.apache.calcite.avatica.util.DateTimeUtils.unixTimestampExtract; -import static org.apache.calcite.avatica.util.DateTimeUtils.unixTimestampToString; -import static org.apache.calcite.avatica.util.DateTimeUtils.ymdToJulian; -import static org.apache.calcite.avatica.util.DateTimeUtils.ymdToUnixDate; - -import static org.hamcrest.CoreMatchers.anyOf; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -/** - * Tests for {@link DateTimeUtils}. - */ -public class DateTimeUtilsTest { - @Test public void testEasyLog10() { - assertEquals(1, digitCount(0)); - assertEquals(1, digitCount(1)); - assertEquals(1, digitCount(9)); - assertEquals(2, digitCount(10)); - assertEquals(2, digitCount(11)); - assertEquals(2, digitCount(99)); - assertEquals(3, digitCount(100)); - } - - @Test public void testFloorDiv() { - assertThat(floorDiv(13, 3), equalTo(4L)); - assertThat(floorDiv(12, 3), equalTo(4L)); - assertThat(floorDiv(11, 3), equalTo(3L)); - assertThat(floorDiv(-13, 3), equalTo(-5L)); - assertThat(floorDiv(-12, 3), equalTo(-4L)); - assertThat(floorDiv(-11, 3), equalTo(-4L)); - assertThat(floorDiv(0, 3), equalTo(0L)); - assertThat(floorDiv(1, 3), equalTo(0L)); - assertThat(floorDiv(-1, 3), is(-1L)); - } - - @Test public void testFloorMod() { - assertThat(floorMod(13, 3), is(1L)); - assertThat(floorMod(12, 3), is(0L)); - assertThat(floorMod(11, 3), is(2L)); - assertThat(floorMod(-13, 3), is(2L)); - assertThat(floorMod(-12, 3), is(0L)); - assertThat(floorMod(-11, 3), is(1L)); - assertThat(floorMod(0, 3), is(0L)); - assertThat(floorMod(1, 3), is(1L)); - assertThat(floorMod(-1, 3), is(2L)); - } - - @Test public void testUnixDateToString() { - // Verify these using the "date" command. E.g. - // $ date -u --date="@$(expr 10957 \* 86400)" - // Sat Jan 1 00:00:00 UTC 2000 - assertEquals("2000-01-01", unixDateToString(10957)); - - assertEquals("1970-01-01", unixDateToString(0)); - assertEquals("1970-01-02", unixDateToString(1)); - assertEquals("1971-01-01", unixDateToString(365)); - assertEquals("1972-01-01", unixDateToString(730)); - assertEquals("1972-02-28", unixDateToString(788)); - assertEquals("1972-02-29", unixDateToString(789)); - assertEquals("1972-03-01", unixDateToString(790)); - - assertEquals("1969-01-01", unixDateToString(-365)); - assertEquals("2000-01-01", unixDateToString(10957)); - assertEquals("2000-02-28", unixDateToString(11015)); - assertEquals("2000-02-29", unixDateToString(11016)); - assertEquals("2000-03-01", unixDateToString(11017)); - assertEquals("1900-01-01", unixDateToString(-25567)); - assertEquals("1900-02-28", unixDateToString(-25509)); - assertEquals("1900-03-01", unixDateToString(-25508)); - assertEquals("1945-02-24", unixDateToString(-9077)); - } - - @Test public void testYmdToUnixDate() { - assertEquals(0, ymdToUnixDate(1970, 1, 1)); - assertEquals(365, ymdToUnixDate(1971, 1, 1)); - assertEquals(-365, ymdToUnixDate(1969, 1, 1)); - assertEquals(11015, ymdToUnixDate(2000, 2, 28)); - assertEquals(11016, ymdToUnixDate(2000, 2, 29)); - assertEquals(11017, ymdToUnixDate(2000, 3, 1)); - assertEquals(-9077, ymdToUnixDate(1945, 2, 24)); - assertEquals(-25509, ymdToUnixDate(1900, 2, 28)); - assertEquals(-25508, ymdToUnixDate(1900, 3, 1)); - } - - @Test public void testDateToString() { - checkDateString("1970-01-01", 0); - //noinspection PointlessArithmeticExpression - checkDateString("1971-02-03", 0 + 365 + 31 + (3 - 1)); - //noinspection PointlessArithmeticExpression - checkDateString("1971-02-28", 0 + 365 + 31 + (28 - 1)); - //noinspection PointlessArithmeticExpression - checkDateString("1971-03-01", 0 + 365 + 31 + 28 + (1 - 1)); - //noinspection PointlessArithmeticExpression - checkDateString("1972-02-28", 0 + 365 * 2 + 31 + (28 - 1)); - //noinspection PointlessArithmeticExpression - checkDateString("1972-02-29", 0 + 365 * 2 + 31 + (29 - 1)); - //noinspection PointlessArithmeticExpression - checkDateString("1972-03-01", 0 + 365 * 2 + 31 + 29 + (1 - 1)); - } - - private void checkDateString(String s, int d) { - assertThat(unixDateToString(d), is(s)); - assertThat(dateStringToUnixDate(s), is(d)); - } - - @Test public void testTimeToString() { - checkTimeString("00:00:00", 0, 0); - checkTimeString("23:59:59", 0, 86400000 - 1000); - checkTimeString("23:59:59.1", 1, 86400000 - 1000 + 100); - checkTimeString("23:59:59.01", 2, 86400000 - 1000 + 10); - checkTimeString("23:59:59.1234", 3, 86400000 - 1000 + 123); - checkTimeString("23:59:59.1236", 3, 86400000 - 1000 + 124); - checkTimeString("23:59:59.123456789012345678901234567890", 3, - 86400000 - 1000 + 123); - } - - @Test public void testTimestampExtract() { - // 1970-01-01 00:00:00.000 - assertThat(unixTimestampExtract(TimeUnitRange.HOUR, 0L), is(0)); - assertThat(unixTimestampExtract(TimeUnitRange.MINUTE, 0L), is(0)); - assertThat(unixTimestampExtract(TimeUnitRange.SECOND, 0L), is(0)); - // 1970-01-02 00:00:00.000 - assertThat(unixTimestampExtract(TimeUnitRange.HOUR, 86400000L), is(0)); - assertThat(unixTimestampExtract(TimeUnitRange.MINUTE, 86400000L), is(0)); - assertThat(unixTimestampExtract(TimeUnitRange.SECOND, 86400000L), is(0)); - } - - @Test public void testTimeExtract() { - // 00:00:00.000 - assertThat(unixTimeExtract(TimeUnitRange.HOUR, 0), is(0)); - assertThat(unixTimeExtract(TimeUnitRange.MINUTE, 0), is(0)); - assertThat(unixTimeExtract(TimeUnitRange.SECOND, 0), is(0)); - // 00:59:59.999 - assertThat(unixTimeExtract(TimeUnitRange.HOUR, 3599999), is(0)); - assertThat(unixTimeExtract(TimeUnitRange.MINUTE, 3599999), is(59)); - assertThat(unixTimeExtract(TimeUnitRange.SECOND, 3599999), is(59)); - // 01:59:59.999 - assertThat(unixTimeExtract(TimeUnitRange.HOUR, 7199999), is(1)); - assertThat(unixTimeExtract(TimeUnitRange.MINUTE, 7199999), is(59)); - assertThat(unixTimeExtract(TimeUnitRange.SECOND, 7199999), is(59)); - // 01:58:59.999 - assertThat(unixTimeExtract(TimeUnitRange.HOUR, 7139999), is(1)); - assertThat(unixTimeExtract(TimeUnitRange.MINUTE, 7139999), is(58)); - assertThat(unixTimeExtract(TimeUnitRange.SECOND, 7139999), is(59)); - // 23:59:59.999 - assertThat(unixTimeExtract(TimeUnitRange.HOUR, 86399999), is(23)); - assertThat(unixTimeExtract(TimeUnitRange.MINUTE, 86399999), is(59)); - assertThat(unixTimeExtract(TimeUnitRange.SECOND, 86399999), is(59)); - } - - private void checkTimeString(String s, int p, int d) { - int digitsAfterPoint = s.indexOf('.') >= 0 - ? s.length() - s.indexOf('.') - 1 - : 0; - if (digitsAfterPoint == p) { - assertThat(unixTimeToString(d, p), is(s)); - } - assertThat(timeStringToUnixDate(s), is(d)); - } - - @Test public void testTimestampToString() { - // ISO format would be "1970-01-01T00:00:00" but SQL format is different - checkTimestampString("1970-01-01 00:00:00", 0, 0L); - checkTimestampString("1970-02-01 23:59:59", 0, 86400000L * 32L - 1000L); - checkTimestampString("1970-02-01 23:59:59.123", 3, - 86400000L * 32L - 1000L + 123); - checkTimestampString("1970-02-01 23:59:59.04", 2, - 86400000L * 32L - 1000L + 40); - } - - private void checkTimestampString(String s, int p, long d) { - assertThat(unixTimestampToString(d, p), is(s)); - assertThat(timestampStringToUnixDate(s), is(d)); - } - - @Test public void testIntervalYearMonthToString() { - TimeUnitRange range = TimeUnitRange.YEAR_TO_MONTH; - assertEquals("+0-00", intervalYearMonthToString(0, range)); - assertEquals("+1-00", intervalYearMonthToString(12, range)); - assertEquals("+1-01", intervalYearMonthToString(13, range)); - assertEquals("-1-01", intervalYearMonthToString(-13, range)); - } - - @Test public void testIntervalDayTimeToString() { - assertEquals("+0", intervalYearMonthToString(0, TimeUnitRange.YEAR)); - assertEquals("+0-00", - intervalYearMonthToString(0, TimeUnitRange.YEAR_TO_MONTH)); - assertEquals("+0", intervalYearMonthToString(0, TimeUnitRange.MONTH)); - assertEquals("+0", intervalDayTimeToString(0, TimeUnitRange.DAY, 0)); - assertEquals("+0 00", - intervalDayTimeToString(0, TimeUnitRange.DAY_TO_HOUR, 0)); - assertEquals("+0 00:00", - intervalDayTimeToString(0, TimeUnitRange.DAY_TO_MINUTE, 0)); - assertEquals("+0 00:00:00", - intervalDayTimeToString(0, TimeUnitRange.DAY_TO_SECOND, 0)); - assertEquals("+0", intervalDayTimeToString(0, TimeUnitRange.HOUR, 0)); - assertEquals("+0:00", - intervalDayTimeToString(0, TimeUnitRange.HOUR_TO_MINUTE, 0)); - assertEquals("+0:00:00", - intervalDayTimeToString(0, TimeUnitRange.HOUR_TO_SECOND, 0)); - assertEquals("+0", - intervalDayTimeToString(0, TimeUnitRange.MINUTE, 0)); - assertEquals("+0:00", - intervalDayTimeToString(0, TimeUnitRange.MINUTE_TO_SECOND, 0)); - assertEquals("+0", - intervalDayTimeToString(0, TimeUnitRange.SECOND, 0)); - } - - @Test public void testYmdToJulian() { - // All checked using http://aa.usno.navy.mil/data/docs/JulianDate.php. - // We round up - if JulianDate.php gives 2451544.5, we use 2451545. - assertThat(ymdToJulian(2014, 4, 3), is(2456751)); - - // 2000 is a leap year - assertThat(ymdToJulian(2000, 1, 1), is(2451545)); - assertThat(ymdToJulian(2000, 2, 28), is(2451603)); - assertThat(ymdToJulian(2000, 2, 29), is(2451604)); - assertThat(ymdToJulian(2000, 3, 1), is(2451605)); - - assertThat(ymdToJulian(1970, 1, 1), is(2440588)); - assertThat(ymdToJulian(1970, 1, 1), is(EPOCH_JULIAN)); - assertThat(ymdToJulian(1901, 1, 1), is(2415386)); - - // 1900 is not a leap year - assertThat(ymdToJulian(1900, 10, 17), is(2415310)); - assertThat(ymdToJulian(1900, 3, 1), is(2415080)); - assertThat(ymdToJulian(1900, 2, 28), is(2415079)); - assertThat(ymdToJulian(1900, 2, 1), is(2415052)); - assertThat(ymdToJulian(1900, 1, 1), is(2415021)); - - assertThat(ymdToJulian(1777, 7, 4), is(2370281)); - - // 2016 is a leap year - assertThat(ymdToJulian(2016, 2, 28), is(2457447)); - assertThat(ymdToJulian(2016, 2, 29), is(2457448)); - assertThat(ymdToJulian(2016, 3, 1), is(2457449)); - } - - @Test public void testExtract() { - assertThat(unixDateExtract(TimeUnitRange.YEAR, 0), is(1970L)); - assertThat(unixDateExtract(TimeUnitRange.YEAR, -1), is(1969L)); - assertThat(unixDateExtract(TimeUnitRange.YEAR, 364), is(1970L)); - assertThat(unixDateExtract(TimeUnitRange.YEAR, 365), is(1971L)); - - assertThat(unixDateExtract(TimeUnitRange.MONTH, 0), is(1L)); - assertThat(unixDateExtract(TimeUnitRange.MONTH, -1), is(12L)); - assertThat(unixDateExtract(TimeUnitRange.MONTH, 364), is(12L)); - assertThat(unixDateExtract(TimeUnitRange.MONTH, 365), is(1L)); - - // 1969/12/31 was a Wed (4) - assertThat(unixDateExtract(TimeUnitRange.DOW, -1), is(4L)); // wed - assertThat(unixDateExtract(TimeUnitRange.DOW, 0), is(5L)); // thu - assertThat(unixDateExtract(TimeUnitRange.DOW, 1), is(6L)); // fri - assertThat(unixDateExtract(TimeUnitRange.DOW, 2), is(7L)); // sat - assertThat(unixDateExtract(TimeUnitRange.DOW, 3), is(1L)); // sun - assertThat(unixDateExtract(TimeUnitRange.DOW, 365), is(6L)); - assertThat(unixDateExtract(TimeUnitRange.DOW, 366), is(7L)); - - assertThat(unixDateExtract(TimeUnitRange.DOY, -1), is(365L)); - assertThat(unixDateExtract(TimeUnitRange.DOY, 0), is(1L)); - assertThat(unixDateExtract(TimeUnitRange.DOY, 1), is(2L)); - assertThat(unixDateExtract(TimeUnitRange.DOY, 2), is(3L)); - assertThat(unixDateExtract(TimeUnitRange.DOY, 3), is(4L)); - assertThat(unixDateExtract(TimeUnitRange.DOY, 364), is(365L)); - assertThat(unixDateExtract(TimeUnitRange.DOY, 365), is(1L)); - assertThat(unixDateExtract(TimeUnitRange.DOY, 366), is(2L)); - assertThat(unixDateExtract(TimeUnitRange.DOY, 365 + 365 + 366 - 1), - is(366L)); // 1972/12/31 - assertThat(unixDateExtract(TimeUnitRange.DOY, 365 + 365 + 366), - is(1L)); // 1973/1/1 - - // The number of the week of the year that the day is in. By definition - // (ISO 8601), the first week of a year contains January 4 of that year. - // (The ISO-8601 week starts on Monday.) In other words, the first Thursday - // of a year is in week 1 of that year. - // - // Because of this, it is possible for early January dates to be part of - // the 52nd or 53rd week of the previous year. For example, 2005-01-01 is - // part of the 53rd week of year 2004, and 2006-01-01 is part of the 52nd - // week of year 2005. - assertThat(ymdToUnixDate(1970, 1, 1), is(0)); - assertThat(unixDateExtract(TimeUnitRange.WEEK, ymdToUnixDate(2003, 1, 1)), - is(1L)); // wed - assertThat(unixDateExtract(TimeUnitRange.WEEK, ymdToUnixDate(2004, 1, 1)), - is(1L)); // thu - assertThat(unixDateExtract(TimeUnitRange.WEEK, ymdToUnixDate(2005, 1, 1)), - is(53L)); // sat - assertThat(unixDateExtract(TimeUnitRange.WEEK, ymdToUnixDate(2006, 1, 1)), - is(52L)); // sun - assertThat(unixDateExtract(TimeUnitRange.WEEK, ymdToUnixDate(1970, 1, 1)), - is(1L)); // thu - - assertThat(unixDateExtract(TimeUnitRange.WEEK, -1), is(53L)); // wed - assertThat(unixDateExtract(TimeUnitRange.WEEK, 0), is(1L)); // thu - assertThat(unixDateExtract(TimeUnitRange.WEEK, 1), is(1L)); // fru - assertThat(unixDateExtract(TimeUnitRange.WEEK, 2), is(1L)); // sat - assertThat(unixDateExtract(TimeUnitRange.WEEK, 3), is(1L)); // sun - assertThat(unixDateExtract(TimeUnitRange.WEEK, 4), is(2L)); // mon - assertThat(unixDateExtract(TimeUnitRange.WEEK, 7), is(2L)); // thu - assertThat(unixDateExtract(TimeUnitRange.WEEK, 10), is(2L)); // sun - assertThat(unixDateExtract(TimeUnitRange.WEEK, 11), is(3L)); // mon - assertThat(unixDateExtract(TimeUnitRange.WEEK, 359), is(52L)); // sat - assertThat(unixDateExtract(TimeUnitRange.WEEK, 360), is(52L)); // sun - assertThat(unixDateExtract(TimeUnitRange.WEEK, 361), is(53L)); // mon - assertThat(unixDateExtract(TimeUnitRange.WEEK, 364), is(53L)); // thu - assertThat(unixDateExtract(TimeUnitRange.WEEK, 365), is(53L)); // fri - assertThat(unixDateExtract(TimeUnitRange.WEEK, 368), is(1L)); // mon - - assertThat(unixDateExtract(TimeUnitRange.QUARTER, -1), is(4L)); - assertThat(unixDateExtract(TimeUnitRange.QUARTER, 0), is(1L)); - assertThat(unixDateExtract(TimeUnitRange.QUARTER, 365), is(1L)); - assertThat(unixDateExtract(TimeUnitRange.QUARTER, 366), is(1L)); - - thereAndBack(1900, 1, 1); - thereAndBack(1900, 2, 28); // no leap day - thereAndBack(1900, 3, 1); - thereAndBack(1901, 1, 1); - thereAndBack(1901, 2, 28); // no leap day - thereAndBack(1901, 3, 1); - thereAndBack(2000, 1, 1); - thereAndBack(2000, 2, 28); - thereAndBack(2000, 2, 29); // leap day - thereAndBack(2000, 3, 1); - thereAndBack(1964, 1, 1); - thereAndBack(1964, 2, 28); - thereAndBack(1964, 2, 29); // leap day - thereAndBack(1964, 3, 1); - thereAndBack(1864, 1, 1); - thereAndBack(1864, 2, 28); - thereAndBack(1864, 2, 29); // leap day - thereAndBack(1864, 3, 1); - thereAndBack(1900, 1, 1); - thereAndBack(1900, 2, 28); - thereAndBack(1900, 3, 1); - thereAndBack(2004, 2, 28); - thereAndBack(2004, 2, 29); // leap day - thereAndBack(2004, 3, 1); - thereAndBack(2005, 2, 28); // no leap day - thereAndBack(2005, 3, 1); - thereAndBack(1601, 1, 1); - // Doesn't work much earlier than 1600 because of leap year differences. - // Before 1600, does the user expect Gregorian calendar? - if (false) { - thereAndBack(1581, 1, 1); - thereAndBack(1, 1, 1); - } - - // Per PostgreSQL: The first century starts at 0001-01-01 00:00:00 AD, - // although they did not know it at the time. This definition applies to - // all Gregorian calendar countries. There is no century number 0, you go - // from -1 century to 1 century. If you disagree with this, please write - // your complaint to: Pope, Cathedral Saint-Peter of Roma, Vatican. - - // The 21st century started on 2001/01/01 - assertThat( - unixDateExtract(TimeUnitRange.CENTURY, ymdToUnixDate(2001, 1, 1)), - is(21L)); - assertThat( - unixDateExtract(TimeUnitRange.CENTURY, ymdToUnixDate(2000, 12, 31)), - is(20L)); - assertThat( - unixDateExtract(TimeUnitRange.CENTURY, ymdToUnixDate(1852, 6, 7)), - is(19L)); - assertThat( - unixDateExtract(TimeUnitRange.CENTURY, ymdToUnixDate(1, 2, 1)), - is(1L)); - // TODO: For a small time range around year 1, due to the Gregorian shift, - // we end up in the wrong century. Should be 1. - assertThat( - unixDateExtract(TimeUnitRange.CENTURY, ymdToUnixDate(1, 1, 1)), - is(0L)); - assertThat( - unixDateExtract(TimeUnitRange.CENTURY, ymdToUnixDate(-2, 1, 1)), - is(-1L)); - - // The 3rd millennium started on 2001/01/01 - assertThat( - unixDateExtract(TimeUnitRange.MILLENNIUM, ymdToUnixDate(2001, 1, 1)), - is(3L)); - assertThat( - unixDateExtract(TimeUnitRange.MILLENNIUM, ymdToUnixDate(2000, 12, 31)), - is(2L)); - assertThat( - unixDateExtract(TimeUnitRange.MILLENNIUM, ymdToUnixDate(1852, 6, 7)), - is(2L)); - // TODO: For a small time range around year 1, due to the Gregorian shift, - // we end up in the wrong millennium. Should be 1. - assertThat( - unixDateExtract(TimeUnitRange.MILLENNIUM, ymdToUnixDate(1, 1, 1)), - is(0L)); - assertThat( - unixDateExtract(TimeUnitRange.MILLENNIUM, ymdToUnixDate(1, 2, 1)), - is(1L)); - assertThat( - unixDateExtract(TimeUnitRange.MILLENNIUM, ymdToUnixDate(-2, 1, 1)), - is(-1L)); - } - - private void thereAndBack(int year, int month, int day) { - final int unixDate = ymdToUnixDate(year, month, day); - assertThat(unixDateExtract(TimeUnitRange.YEAR, unixDate), - is((long) year)); - assertThat(unixDateExtract(TimeUnitRange.MONTH, unixDate), - is((long) month)); - assertThat(unixDateExtract(TimeUnitRange.DAY, unixDate), - is((long) day)); - final long w = unixDateExtract(TimeUnitRange.WEEK, unixDate); - assertTrue(w >= 1 && w <= 53); - final long dow = unixDateExtract(TimeUnitRange.DOW, unixDate); - assertTrue(dow >= 1 && dow <= 7); - final long doy = unixDateExtract(TimeUnitRange.DOY, unixDate); - assertTrue(doy >= 1 && dow <= 366); - final long q = unixDateExtract(TimeUnitRange.QUARTER, unixDate); - assertTrue(q >= 1 && q <= 4); - final long c = unixDateExtract(TimeUnitRange.CENTURY, unixDate); - assertTrue(c == (year > 0 ? (year + 99) / 100 : (year - 99) / 100)); - final long m = unixDateExtract(TimeUnitRange.MILLENNIUM, unixDate); - assertTrue(m == (year > 0 ? (year + 999) / 1000 : (year - 999) / 1000)); - } - - @Test public void testAddMonths() { - checkAddMonths(2016, 1, 1, 2016, 2, 1, 1); - checkAddMonths(2016, 1, 1, 2017, 1, 1, 12); - checkAddMonths(2016, 1, 1, 2017, 2, 1, 13); - checkAddMonths(2016, 1, 1, 2015, 1, 1, -12); - checkAddMonths(2016, 1, 1, 2018, 10, 1, 33); - checkAddMonths(2016, 1, 31, 2016, 5, 1, 3); // roll up - checkAddMonths(2016, 4, 30, 2016, 7, 30, 3); // roll up - checkAddMonths(2016, 1, 31, 2016, 3, 1, 1); - checkAddMonths(2016, 3, 31, 2016, 3, 1, -1); - checkAddMonths(2016, 3, 31, 2116, 3, 31, 1200); - checkAddMonths(2016, 2, 28, 2116, 2, 28, 1200); - } - - private void checkAddMonths(int y0, int m0, int d0, int y1, int m1, int d1, - int months) { - final int date0 = ymdToUnixDate(y0, m0, d0); - final long date = addMonths(date0, months); - final int date1 = ymdToUnixDate(y1, m1, d1); - assertThat((int) date, is(date1)); - - assertThat(subtractMonths(date1, date0), - anyOf(is(months), is(months + 1))); - assertThat(subtractMonths(date1 + 1, date0), - anyOf(is(months), is(months + 1))); - assertThat(subtractMonths(date1, date0 + 1), - anyOf(is(months), is(months - 1))); - assertThat(subtractMonths(d2ts(date1, 1), d2ts(date0, 0)), - anyOf(is(months), is(months + 1))); - assertThat(subtractMonths(d2ts(date1, 0), d2ts(date0, 1)), - anyOf(is(months - 1), is(months), is(months + 1))); - } - - /** Converts a date (days since epoch) and milliseconds (since midnight) - * into a timestamp (milliseconds since epoch). */ - private long d2ts(int date, int millis) { - return date * DateTimeUtils.MILLIS_PER_DAY + millis; - } - - @Test public void testUnixTimestamp() { - assertThat(unixTimestamp(1970, 1, 1, 0, 0, 0), is(0L)); - final long day = 86400000L; - assertThat(unixTimestamp(1970, 1, 2, 0, 0, 0), is(day)); - assertThat(unixTimestamp(1970, 1, 1, 23, 59, 59), is(86399000L)); - - // 1900 is not a leap year - final long y1900 = -2203977600000L; - assertThat(unixTimestamp(1900, 2, 28, 0, 0, 0), is(y1900)); - assertThat(unixTimestamp(1900, 3, 1, 0, 0, 0), is(y1900 + day)); - - // 2000 is a leap year - final long y2k = 951696000000L; - assertThat(unixTimestamp(2000, 2, 28, 0, 0, 0), is(y2k)); - assertThat(unixTimestamp(2000, 2, 29, 0, 0, 0), is(y2k + day)); - assertThat(unixTimestamp(2000, 3, 1, 0, 0, 0), is(y2k + day + day)); - - // 2016 is a leap year - final long y2016 = 1456617600000L; - assertThat(unixTimestamp(2016, 2, 28, 0, 0, 0), is(y2016)); - assertThat(unixTimestamp(2016, 2, 29, 0, 0, 0), is(y2016 + day)); - assertThat(unixTimestamp(2016, 3, 1, 0, 0, 0), is(y2016 + day + day)); - } -} - -// End DateTimeUtilsTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/test/java/org/apache/calcite/avatica/util/NumberAccessorTest.java ---------------------------------------------------------------------- diff --git a/avatica/core/src/test/java/org/apache/calcite/avatica/util/NumberAccessorTest.java b/avatica/core/src/test/java/org/apache/calcite/avatica/util/NumberAccessorTest.java deleted file mode 100644 index f1b2ef1..0000000 --- a/avatica/core/src/test/java/org/apache/calcite/avatica/util/NumberAccessorTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.util; - -import org.apache.calcite.avatica.util.AbstractCursor.Getter; -import org.apache.calcite.avatica.util.AbstractCursor.NumberAccessor; - -import org.junit.Test; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.sql.SQLException; - -import static org.junit.Assert.assertEquals; - -/** - * Test logic for the NumberAccessor. - */ -public class NumberAccessorTest { - - @Test - public void testBigDecimalZeroScale() throws SQLException { - final BigDecimal orig = new BigDecimal(BigInteger.valueOf(137L), 1); - NumberAccessor accessor = new AbstractCursor.NumberAccessor( - new Getter() { - @Override public Object getObject() { - return orig; - } - - @Override public boolean wasNull() { - return false; - } - }, - 0); - - assertEquals(orig, accessor.getBigDecimal(0)); - } - -} - -// End NumberAccessorTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/core/src/test/java/org/apache/calcite/avatica/util/UnsynchronizedBufferTest.java ---------------------------------------------------------------------- diff --git a/avatica/core/src/test/java/org/apache/calcite/avatica/util/UnsynchronizedBufferTest.java b/avatica/core/src/test/java/org/apache/calcite/avatica/util/UnsynchronizedBufferTest.java deleted file mode 100644 index a448d3e..0000000 --- a/avatica/core/src/test/java/org/apache/calcite/avatica/util/UnsynchronizedBufferTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.util; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * Tests for the UnsynchronizedBuffer. - */ -public class UnsynchronizedBufferTest { - - @Test public void testArrayResizing() { - int size = 64; - int expected = 128; - for (int i = 0; i < 10; i++) { - // We keep being one byte short to contain this message - int next = UnsynchronizedBuffer.nextArraySize(size + 1); - assertEquals(expected, next); - size = next; - expected *= 2; - } - } -} - -// End UnsynchronizedBufferTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/pom.xml ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/pom.xml b/avatica/metrics-dropwizardmetrics3/pom.xml deleted file mode 100644 index bd60ffe..0000000 --- a/avatica/metrics-dropwizardmetrics3/pom.xml +++ /dev/null @@ -1,117 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one or more -contributor license agreements. See the NOTICE file distributed with -this work for additional information regarding copyright ownership. -The ASF licenses this file to you under the Apache License, Version 2.0 -(the "License"); you may not use this file except in compliance with -the License. You may obtain a copy of the License at - -http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.calcite.avatica</groupId> - <artifactId>avatica-parent</artifactId> - <version>1.10.0-SNAPSHOT</version> - </parent> - - <artifactId>avatica-metrics-dropwizardmetrics3</artifactId> - <packaging>jar</packaging> - <name>Apache Calcite Avatica Dropwizard Metrics 3</name> - <description>An implementation of Avatica Metrics using Dropwizard Metrics.</description> - - <properties> - <top.dir>${project.basedir}/..</top.dir> - </properties> - - <dependencies> - <dependency> - <groupId>org.apache.calcite.avatica</groupId> - <artifactId>avatica-metrics</artifactId> - </dependency> - <dependency> - <groupId>io.dropwizard.metrics</groupId> - <artifactId>metrics-core</artifactId> - <!-- Avoid specifying version in dependencyManagement in support of other avatica-metrics impls --> - <version>${dropwizard-metrics3.version}</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <pluginManagement> - <plugins> - <plugin> - <groupId>org.eclipse.m2e</groupId> - <artifactId>lifecycle-mapping</artifactId> - <version>1.0.0</version> - <configuration> - <lifecycleMappingMetadata> - <pluginExecutions> - <pluginExecution> - <pluginExecutionFilter> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-checkstyle-plugin</artifactId> - <versionRange>[2.12.1,)</versionRange> - <goals> - <goal>check</goal> - </goals> - </pluginExecutionFilter> - <action> - <ignore /> - </action> - </pluginExecution> - </pluginExecutions> - </lifecycleMappingMetadata> - </configuration> - </plugin> - </plugins> - </pluginManagement> - <plugins> - <!-- Parent module has the same plugin and does the work of - generating -sources.jar for each project. But without the - plugin declared here, IDEs don't know the sources are - available. --> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-source-plugin</artifactId> - <executions> - <execution> - <id>attach-sources</id> - <phase>verify</phase> - <goals> - <goal>jar-no-fork</goal> - <goal>test-jar-no-fork</goal> - </goals> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.rat</groupId> - <artifactId>apache-rat-plugin</artifactId> - <configuration> - <excludes> - <exclude>src/main/resources/META-INF/services/org.apache.calcite.avatica.metrics.MetricsSystemFactory</exclude> - </excludes> - </configuration> - </plugin> - </plugins> - </build> -</project> http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardCounter.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardCounter.java b/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardCounter.java deleted file mode 100644 index 4204ebf..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardCounter.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.metrics.dropwizard3; - -import com.codahale.metrics.Counter; - -import java.util.Objects; - -/** - * Dropwizard Metrics implementation of {@link org.apache.calcite.avatica.metrics.Counter}. - */ -public class DropwizardCounter implements org.apache.calcite.avatica.metrics.Counter { - - private final Counter counter; - - public DropwizardCounter(Counter counter) { - this.counter = Objects.requireNonNull(counter); - } - - @Override public void increment() { - this.counter.inc(); - } - - @Override public void increment(long n) { - this.counter.inc(n); - } - - @Override public void decrement() { - this.counter.dec(); - } - - @Override public void decrement(long n) { - this.counter.dec(n); - } -} - -// End DropwizardCounter.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardGauge.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardGauge.java b/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardGauge.java deleted file mode 100644 index 5f4b776..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardGauge.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.metrics.dropwizard3; - -import com.codahale.metrics.Gauge; - -/** - * Dropwizard Metrics implementation of {@link org.apache.calcite.avatica.metrics.Gauge}. - * - * @param <T> The value the gauge returns. - */ -public class DropwizardGauge<T> implements Gauge<T> { - - private final org.apache.calcite.avatica.metrics.Gauge<T> gauge; - - public DropwizardGauge(org.apache.calcite.avatica.metrics.Gauge<T> gauge) { - this.gauge = gauge; - } - - @Override public T getValue() { - return gauge.getValue(); - } -} - -// End DropwizardGauge.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardHistogram.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardHistogram.java b/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardHistogram.java deleted file mode 100644 index 266f130..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardHistogram.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.metrics.dropwizard3; - -import com.codahale.metrics.Histogram; - -import java.util.Objects; - -/** - * Dropwizard metrics implementation of {@link org.apache.calcite.avatica.metrics.Histogram}. - */ -public class DropwizardHistogram implements org.apache.calcite.avatica.metrics.Histogram { - - private final Histogram histogram; - - public DropwizardHistogram(Histogram histogram) { - this.histogram = Objects.requireNonNull(histogram); - } - - @Override public void update(int value) { - histogram.update(value); - } - - @Override public void update(long value) { - histogram.update(value); - } -} - -// End DropwizardHistogram.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMeter.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMeter.java b/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMeter.java deleted file mode 100644 index ab8fafc..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMeter.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.metrics.dropwizard3; - -import com.codahale.metrics.Meter; - -import java.util.Objects; - -/** - * Dropwizard metrics implementation of {@link org.apache.calcite.avatica.metrics.Meter}. - */ -public class DropwizardMeter implements org.apache.calcite.avatica.metrics.Meter { - - private final Meter meter; - - public DropwizardMeter(Meter meter) { - this.meter = Objects.requireNonNull(meter); - } - - @Override public void mark() { - this.meter.mark(); - } - - @Override public void mark(long count) { - this.meter.mark(count); - } -} - -// End DropwizardMeter.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystem.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystem.java b/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystem.java deleted file mode 100644 index 6aa71b9..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystem.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.metrics.dropwizard3; - -import org.apache.calcite.avatica.metrics.Counter; -import org.apache.calcite.avatica.metrics.Gauge; -import org.apache.calcite.avatica.metrics.Histogram; -import org.apache.calcite.avatica.metrics.Meter; -import org.apache.calcite.avatica.metrics.MetricsSystem; -import org.apache.calcite.avatica.metrics.Timer; - -import com.codahale.metrics.MetricRegistry; - -import java.util.Objects; - -/** - * Dropwizard Metrics implementation of {@link MetricsSystem}. - */ -public class DropwizardMetricsSystem implements MetricsSystem { - - private final MetricRegistry registry; - - public DropwizardMetricsSystem(MetricRegistry registry) { - this.registry = Objects.requireNonNull(registry); - } - - @Override public Timer getTimer(String name) { - return new DropwizardTimer(registry.timer(name)); - } - - @Override public Histogram getHistogram(String name) { - return new DropwizardHistogram(registry.histogram(name)); - } - - @Override public Meter getMeter(String name) { - return new DropwizardMeter(registry.meter(name)); - } - - @Override public Counter getCounter(String name) { - return new DropwizardCounter(registry.counter(name)); - } - - @Override public <T> void register(String name, Gauge<T> gauge) { - registry.register(name, new DropwizardGauge<T>(gauge)); - } -} - -// End DropwizardMetricsSystem.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemConfiguration.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemConfiguration.java b/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemConfiguration.java deleted file mode 100644 index f4c9234..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemConfiguration.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.metrics.dropwizard3; - -import org.apache.calcite.avatica.metrics.MetricsSystemConfiguration; - -import com.codahale.metrics.MetricRegistry; - -import java.util.Objects; - -/** - * A container which provides a {@link MetricRegistry} to a {@link DropwizardMetricsSystem}. - */ -public class DropwizardMetricsSystemConfiguration implements - MetricsSystemConfiguration<MetricRegistry> { - - private final MetricRegistry registry; - - public DropwizardMetricsSystemConfiguration(MetricRegistry registry) { - this.registry = Objects.requireNonNull(registry); - } - - @Override public MetricRegistry get() { - return registry; - } -} - -// End DropwizardMetricsSystemConfiguration.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemFactory.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemFactory.java b/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemFactory.java deleted file mode 100644 index 1480db6..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemFactory.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.metrics.dropwizard3; - -import org.apache.calcite.avatica.metrics.MetricsSystemConfiguration; -import org.apache.calcite.avatica.metrics.MetricsSystemFactory; - -/** - * A {@link MetricsSystemFactory} for {@link DropwizardMetricsSystem}. - */ -public class DropwizardMetricsSystemFactory implements MetricsSystemFactory { - - @Override public DropwizardMetricsSystem create(MetricsSystemConfiguration<?> config) { - // Verify we got configuration this factory can use - if (config instanceof DropwizardMetricsSystemConfiguration) { - DropwizardMetricsSystemConfiguration typedConfig = - (DropwizardMetricsSystemConfiguration) config; - - return new DropwizardMetricsSystem(typedConfig.get()); - } - - throw new IllegalStateException("Expected instance of " - + DropwizardMetricsSystemConfiguration.class.getName() + " but got " - + (null == config ? "null" : config.getClass().getName())); - } -} - -// End DropwizardMetricsSystemFactory.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardTimer.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardTimer.java b/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardTimer.java deleted file mode 100644 index 850f9a6..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardTimer.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.metrics.dropwizard3; - -import com.codahale.metrics.Timer; - -import java.util.Objects; - -/** - * Dropwizard Metrics implementation of {@link org.apache.calcite.avatica.metrics.Timer}. - */ -public class DropwizardTimer implements org.apache.calcite.avatica.metrics.Timer { - - private final Timer timer; - - public DropwizardTimer(Timer timer) { - this.timer = Objects.requireNonNull(timer); - } - - @Override public DropwizardContext start() { - return new DropwizardContext(timer.time()); - } - - /** - * Dropwizard Metrics implementation of {@link org.apache.calcite.avatica.metrics.Timer.Context} - */ - public class DropwizardContext implements org.apache.calcite.avatica.metrics.Timer.Context { - private final com.codahale.metrics.Timer.Context context; - - public DropwizardContext(com.codahale.metrics.Timer.Context context) { - this.context = Objects.requireNonNull(context); - } - - @Override public void close() { - this.context.stop(); - } - } -} - -// End DropwizardTimer.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/package-info.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/package-info.java b/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/package-info.java deleted file mode 100644 index f88df93..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/main/java/org/apache/calcite/avatica/metrics/dropwizard3/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * Dropwizard-Metrics (v3) implementation of the Avatica Metrics framework. - */ -@PackageMarker -package org.apache.calcite.avatica.metrics.dropwizard3; - -import org.apache.calcite.avatica.metrics.PackageMarker; - -// End package-info.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/main/resources/META-INF/services/org.apache.calcite.avatica.metrics.MetricsSystemFactory ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/main/resources/META-INF/services/org.apache.calcite.avatica.metrics.MetricsSystemFactory b/avatica/metrics-dropwizardmetrics3/src/main/resources/META-INF/services/org.apache.calcite.avatica.metrics.MetricsSystemFactory deleted file mode 100644 index 25b64a8..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/main/resources/META-INF/services/org.apache.calcite.avatica.metrics.MetricsSystemFactory +++ /dev/null @@ -1,2 +0,0 @@ -org.apache.calcite.avatica.metrics.dropwizard3.DropwizardMetricsSystemFactory - http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardCounterTest.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardCounterTest.java b/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardCounterTest.java deleted file mode 100644 index b037196..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardCounterTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.metrics.dropwizard3; - -import com.codahale.metrics.Counter; - -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * Test class for {@link DropwizardCounter}. - */ -public class DropwizardCounterTest { - - private Counter counter; - - @Before public void setup() { - this.counter = new Counter(); - } - - @Test public void testCounting() { - DropwizardCounter dwCounter = new DropwizardCounter(counter); - - dwCounter.increment(); - assertEquals(1L, counter.getCount()); - dwCounter.increment(); - assertEquals(2L, counter.getCount()); - dwCounter.increment(2L); - assertEquals(4L, counter.getCount()); - dwCounter.increment(-1L); - assertEquals(3L, counter.getCount()); - - dwCounter.decrement(); - assertEquals(2L, counter.getCount()); - dwCounter.decrement(); - assertEquals(1L, counter.getCount()); - dwCounter.decrement(4L); - assertEquals(-3L, counter.getCount()); - dwCounter.decrement(-3L); - assertEquals(0L, counter.getCount()); - } - -} - -// End DropwizardCounterTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardGaugeTest.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardGaugeTest.java b/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardGaugeTest.java deleted file mode 100644 index ed78a58..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardGaugeTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.metrics.dropwizard3; - -import org.apache.calcite.avatica.metrics.Gauge; - -import org.junit.Test; - -import java.util.concurrent.atomic.AtomicLong; - -import static org.junit.Assert.assertEquals; - -/** - * Test class for {@link DropwizardGauge}. - */ -public class DropwizardGaugeTest { - - @Test public void test() { - SimpleGauge gauge = new SimpleGauge(); - DropwizardGauge<Long> dwGauge = new DropwizardGauge<>(gauge); - - assertEquals(gauge.getValue(), dwGauge.getValue()); - - gauge.setValue(1000L); - - assertEquals(gauge.getValue(), dwGauge.getValue()); - } - - /** - * Gauge implementation with a setter. - */ - private static class SimpleGauge implements Gauge<Long> { - - private final AtomicLong value = new AtomicLong(0L); - - @Override public Long getValue() { - return this.value.get(); - } - - public void setValue(long value) { - this.value.set(value); - } - } -} - -// End DropwizardGaugeTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardHistogramTest.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardHistogramTest.java b/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardHistogramTest.java deleted file mode 100644 index 25ec5c0..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardHistogramTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.metrics.dropwizard3; - -import com.codahale.metrics.Histogram; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -/** - * Test class for {@link DropwizardHistogram}. - */ -public class DropwizardHistogramTest { - - private Histogram histogram; - - @Before public void setup() { - this.histogram = Mockito.mock(Histogram.class); - } - - @Test public void test() { - DropwizardHistogram dwHistogram = new DropwizardHistogram(histogram); - - dwHistogram.update(10); - - dwHistogram.update(100L); - - Mockito.verify(histogram).update(10); - Mockito.verify(histogram).update(100L); - } - -} - -// End DropwizardHistogramTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMeterTest.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMeterTest.java b/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMeterTest.java deleted file mode 100644 index c76c7e0..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMeterTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.metrics.dropwizard3; - -import com.codahale.metrics.Meter; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -/** - * Test class for {@link DropwizardMeter}. - */ -public class DropwizardMeterTest { - - private Meter meter; - - @Before public void setup() { - this.meter = Mockito.mock(Meter.class); - } - - @Test public void test() { - DropwizardMeter dwMeter = new DropwizardMeter(this.meter); - - dwMeter.mark(); - dwMeter.mark(10L); - dwMeter.mark(); - dwMeter.mark(); - - Mockito.verify(meter, Mockito.times(3)).mark(); - Mockito.verify(meter).mark(10L); - } - -} - -// End DropwizardMeterTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemFactoryTest.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemFactoryTest.java b/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemFactoryTest.java deleted file mode 100644 index 332c6e0..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemFactoryTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.metrics.dropwizard3; - -import org.apache.calcite.avatica.metrics.noop.NoopMetricsSystemConfiguration; - -import com.codahale.metrics.MetricRegistry; - -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertNotNull; - -/** - * Test class for {@link DropwizardMetricsSystemFactory}. - */ -public class DropwizardMetricsSystemFactoryTest { - - private DropwizardMetricsSystemFactory factory; - - @Before public void setup() { - factory = new DropwizardMetricsSystemFactory(); - } - - @Test(expected = IllegalStateException.class) public void testNullConfigurationFails() { - factory.create(null); - } - - @Test(expected = IllegalStateException.class) public void testUnhandledConfigurationType() { - factory.create(NoopMetricsSystemConfiguration.getInstance()); - } - - @Test public void testHandledConfigurationType() { - DropwizardMetricsSystem metrics = - factory.create(new DropwizardMetricsSystemConfiguration(new MetricRegistry())); - assertNotNull("Expected DropwizardMetricsSystem to be non-null", metrics); - } -} - -// End DropwizardMetricsSystemFactoryTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemTest.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemTest.java b/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemTest.java deleted file mode 100644 index 7eeec3b..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardMetricsSystemTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.metrics.dropwizard3; - -import org.apache.calcite.avatica.metrics.Counter; -import org.apache.calcite.avatica.metrics.Gauge; -import org.apache.calcite.avatica.metrics.Histogram; -import org.apache.calcite.avatica.metrics.Meter; -import org.apache.calcite.avatica.metrics.Timer; -import org.apache.calcite.avatica.metrics.Timer.Context; - -import com.codahale.metrics.MetricRegistry; - -import org.junit.Before; -import org.junit.Test; - -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** - * Tests for {@link DropwizardMetricsSystem}. - */ -public class DropwizardMetricsSystemTest { - - private MetricRegistry mockRegistry; - private DropwizardMetricsSystem metrics; - - @Before public void setup() { - mockRegistry = mock(MetricRegistry.class); - metrics = new DropwizardMetricsSystem(mockRegistry); - } - - @Test public void testGauge() { - final long gaugeValue = 42L; - final String name = "gauge"; - metrics.register(name, new Gauge<Long>() { - @Override public Long getValue() { - return gaugeValue; - } - }); - - verify(mockRegistry, times(1)).register(eq(name), any(com.codahale.metrics.Gauge.class)); - } - - @Test public void testMeter() { - final String name = "meter"; - final com.codahale.metrics.Meter mockMeter = mock(com.codahale.metrics.Meter.class); - - when(mockRegistry.meter(name)).thenReturn(mockMeter); - - Meter meter = metrics.getMeter(name); - - final long count = 5; - meter.mark(count); - - verify(mockMeter, times(1)).mark(count); - - meter.mark(); - - verify(mockMeter, times(1)).mark(); - } - - @Test public void testHistogram() { - final String name = "histogram"; - final com.codahale.metrics.Histogram mockHistogram = mock(com.codahale.metrics.Histogram.class); - - when(mockRegistry.histogram(name)).thenReturn(mockHistogram); - - Histogram histogram = metrics.getHistogram(name); - - long[] long_values = new long[] {1L, 5L, 15L, 30L, 60L}; - for (long value : long_values) { - histogram.update(value); - } - - for (long value : long_values) { - verify(mockHistogram).update(value); - } - - int[] int_values = new int[] {2, 6, 16, 31, 61}; - for (int value : int_values) { - histogram.update(value); - } - - for (int value : int_values) { - verify(mockHistogram).update(value); - } - } - - @Test public void testCounter() { - final String name = "counter"; - final com.codahale.metrics.Counter mockCounter = mock(com.codahale.metrics.Counter.class); - - when(mockRegistry.counter(name)).thenReturn(mockCounter); - - Counter counter = metrics.getCounter(name); - - long[] updates = new long[] {1L, 5L, -2L, 4L, -8L, 0}; - for (long update : updates) { - if (update < 0) { - counter.decrement(Math.abs(update)); - } else { - counter.increment(update); - } - } - - for (long update : updates) { - if (update < 0) { - verify(mockCounter).dec(Math.abs(update)); - } else { - verify(mockCounter).inc(update); - } - } - - int numSingleUpdates = 3; - for (int i = 0; i < numSingleUpdates; i++) { - counter.increment(); - counter.decrement(); - } - - verify(mockCounter, times(numSingleUpdates)).inc(); - verify(mockCounter, times(numSingleUpdates)).dec(); - } - - @Test public void testTimer() { - final String name = "timer"; - final com.codahale.metrics.Timer mockTimer = mock(com.codahale.metrics.Timer.class); - final com.codahale.metrics.Timer.Context mockContext = - mock(com.codahale.metrics.Timer.Context.class); - - when(mockRegistry.timer(name)).thenReturn(mockTimer); - when(mockTimer.time()).thenReturn(mockContext); - - Timer timer = metrics.getTimer(name); - Context context = timer.start(); - context.close(); - - verify(mockTimer).time(); - verify(mockContext).stop(); - } -} - -// End DropwizardMetricsSystemTest.java http://git-wip-us.apache.org/repos/asf/calcite-avatica/blob/fc7b26c8/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardTimerTest.java ---------------------------------------------------------------------- diff --git a/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardTimerTest.java b/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardTimerTest.java deleted file mode 100644 index 536d935..0000000 --- a/avatica/metrics-dropwizardmetrics3/src/test/java/org/apache/calcite/avatica/metrics/dropwizard3/DropwizardTimerTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to you under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.calcite.avatica.metrics.dropwizard3; - -import org.apache.calcite.avatica.metrics.dropwizard3.DropwizardTimer.DropwizardContext; - -import com.codahale.metrics.Timer; -import com.codahale.metrics.Timer.Context; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; - -/** - * Test class for {@link DropwizardTimer} - */ -public class DropwizardTimerTest { - - private Timer timer; - private Context context; - - @Before public void setup() { - this.timer = Mockito.mock(Timer.class); - this.context = Mockito.mock(Context.class); - } - - @Test public void test() { - DropwizardTimer dwTimer = new DropwizardTimer(timer); - - Mockito.when(timer.time()).thenReturn(context); - - DropwizardContext dwContext = dwTimer.start(); - - dwContext.close(); - - Mockito.verify(timer).time(); - Mockito.verify(context).stop(); - } - -} - -// End DropwizardTimerTest.java
