From 15632b37c2bff2713134f92b196d28220cecfdc8 Mon Sep 17 00:00:00 2001 From: Ilya Kasnacheev Date: Fri, 7 Dec 2018 17:16:40 +0300 Subject: [PATCH] IGNITE-10594 Remove specific JSR310 handling, add java.time test to regular suite. --- .../internal/processors/query/QueryUtils.java | 9 +- .../util/Jsr310Java8DateTimeApiUtils.java | 80 ---- .../processors/query/h2/H2DatabaseType.java | 14 +- .../processors/query/h2/dml/DmlUtils.java | 43 +- ...QueryEntityWithDateTimeApiFieldsTest.java} | 380 ++++++++++-------- .../IgniteBinaryCacheQueryTestSuite2.java | 3 + ...eryJsr310Java8DateTimeApiAbstractTest.java | 72 ---- ...sr310Java8DateTimeApiSupportTestSuite.java | 42 -- 8 files changed, 247 insertions(+), 396 deletions(-) delete mode 100644 modules/core/src/main/java/org/apache/ignite/internal/util/Jsr310Java8DateTimeApiUtils.java rename modules/indexing/src/test/{java8/org/apache/ignite/internal/processors/query/h2/CacheQueryEntityWithJsr310Java8DateTimeApiFieldsTest.java => java/org/apache/ignite/internal/processors/query/h2/CacheQueryEntityWithDateTimeApiFieldsTest.java} (72%) delete mode 100644 modules/indexing/src/test/java8/org/apache/ignite/internal/processors/query/h2/CacheQueryJsr310Java8DateTimeApiAbstractTest.java delete mode 100644 modules/indexing/src/test/java8/org/apache/ignite/testsuites/CacheQueryJsr310Java8DateTimeApiSupportTestSuite.java diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java index e251bd6dd5af3..c90c45c657357 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java @@ -21,6 +21,9 @@ import java.math.BigDecimal; import java.sql.Time; import java.sql.Timestamp; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -58,7 +61,6 @@ import org.apache.ignite.internal.processors.query.property.QueryPropertyAccessor; import org.apache.ignite.internal.processors.query.property.QueryReadOnlyMethodsAccessor; import org.apache.ignite.internal.processors.query.schema.SchemaOperationException; -import org.apache.ignite.internal.util.Jsr310Java8DateTimeApiUtils; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.A; import org.apache.ignite.internal.util.typedef.internal.U; @@ -126,13 +128,14 @@ public class QueryUtils { Timestamp.class, Date.class, java.sql.Date.class, + LocalTime.class, + LocalDate.class, + LocalDateTime.class, String.class, UUID.class, byte[].class )); - sqlClasses.addAll(Jsr310Java8DateTimeApiUtils.jsr310ApiClasses()); - return sqlClasses; } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/Jsr310Java8DateTimeApiUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/Jsr310Java8DateTimeApiUtils.java deleted file mode 100644 index 9febf19c917ce..0000000000000 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/Jsr310Java8DateTimeApiUtils.java +++ /dev/null @@ -1,80 +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.ignite.internal.util; - -import org.apache.ignite.internal.util.typedef.internal.U; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.Collection; - -/** - * Provides utility functions for JSR-310 Java 8 Date and Time API types - * based on reflection. - */ -public final class Jsr310Java8DateTimeApiUtils { - /** Class. */ - private static final Class LOCAL_TIME_CLASS = U.classForName("java.time.LocalTime", null); - - /** Class. */ - private static final Class LOCAL_DATE_CLASS = U.classForName("java.time.LocalDate", null); - - /** Class. */ - private static final Class LOCAL_DATE_TIME_CLASS = U.classForName("java.time.LocalDateTime", null); - - /** JSR-310 API classes. */ - private static final Collection> JSR_310_API_CLASSES = createJsr310ApiClassesCollection(); - - /** - * Creates a collection of the available JSR-310 classes. - * - * @return Collection of the available JSR-310 classes. - */ - @NotNull private static Collection> createJsr310ApiClassesCollection() { - Collection> res = new ArrayList<>(3); - - if (LOCAL_DATE_CLASS != null) - res.add(LOCAL_DATE_CLASS); - - if (LOCAL_TIME_CLASS != null) - res.add(LOCAL_TIME_CLASS); - - if (LOCAL_DATE_TIME_CLASS != null) - res.add(LOCAL_DATE_TIME_CLASS); - - return res; - } - - /** - * Default private constructor. - * - *

Prevents creation of instances of this class.

- */ - private Jsr310Java8DateTimeApiUtils() { - // No-op - } - - /** - * Returns the available JSR-310 classes. - * - * @return Available JSR-310 classes. - */ - @NotNull public static Collection> jsr310ApiClasses() { - return JSR_310_API_CLASSES; - } -} diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DatabaseType.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DatabaseType.java index 3d7faca7b449f..ea7449a55b636 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DatabaseType.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2DatabaseType.java @@ -143,14 +143,12 @@ public static H2DatabaseType fromClass(Class cls) { if (DataType.isGeometryClass(cls)) return GEOMETRY; - if (LocalDateTimeUtils.isJava8DateApiPresent()) { - if (LocalDateTimeUtils.LOCAL_DATE == cls) - return DATE; - else if (LocalDateTimeUtils.LOCAL_TIME == cls) - return TIME; - else if (LocalDateTimeUtils.LOCAL_DATE_TIME == cls) - return TIMESTAMP; - } + if (LocalDateTimeUtils.LOCAL_DATE == cls) + return DATE; + else if (LocalDateTimeUtils.LOCAL_TIME == cls) + return TIME; + else if (LocalDateTimeUtils.LOCAL_DATE_TIME == cls) + return TIMESTAMP; return cls.isArray() && !cls.getComponentType().isPrimitive() ? ARRAY : OTHER; } diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java index 36355fbc1cf6f..7be823d0fe7dc 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java @@ -59,41 +59,41 @@ public static Object convert(Object val, GridH2RowDescriptor desc, Class expC Class currCls = val.getClass(); try { - if (val instanceof Date && currCls != Date.class && expCls == Date.class) { - // H2 thinks that java.util.Date is always a Timestamp, while binary marshaller expects - // precise Date instance. Let's satisfy it. + // H2 thinks that java.util.Date is always a Timestamp, while binary marshaller expects + // precise Date instance. Let's satisfy it. + if (val instanceof Date && currCls != Date.class && expCls == Date.class) return new Date(((Date) val).getTime()); - } // User-given UUID is always serialized by H2 to byte array, so we have to deserialize manually - if (type == Value.UUID && currCls == byte[].class) - return U.unmarshal(desc.context().marshaller(), (byte[]) val, + if (type == Value.UUID && currCls == byte[].class) { + return U.unmarshal(desc.context().marshaller(), (byte[])val, U.resolveClassLoader(desc.context().gridConfig())); + } - if (LocalDateTimeUtils.isJava8DateApiPresent()) { - if (val instanceof Timestamp && LocalDateTimeUtils.LOCAL_DATE_TIME ==expCls) - return LocalDateTimeUtils.valueToLocalDateTime(ValueTimestamp.get((Timestamp) val)); - - if (val instanceof Date && LocalDateTimeUtils.LOCAL_DATE == expCls) - return LocalDateTimeUtils.valueToLocalDate(ValueDate.fromDateValue( - DateTimeUtils.dateValueFromDate(((Date) val).getTime()))); + if (val instanceof Timestamp && LocalDateTimeUtils.LOCAL_DATE_TIME == expCls) + return LocalDateTimeUtils.valueToLocalDateTime(ValueTimestamp.get((Timestamp)val)); - if (val instanceof Time && LocalDateTimeUtils.LOCAL_TIME == expCls) - return LocalDateTimeUtils.valueToLocalTime(ValueTime.get((Time) val)); + if (val instanceof Date && LocalDateTimeUtils.LOCAL_DATE == expCls) { + return LocalDateTimeUtils.valueToLocalDate(ValueDate.fromDateValue( + DateTimeUtils.dateValueFromDate(((Date)val).getTime()))); } + if (val instanceof Time && LocalDateTimeUtils.LOCAL_TIME == expCls) + return LocalDateTimeUtils.valueToLocalTime(ValueTime.get((Time)val)); + // We have to convert arrays of reference types manually - // see https://issues.apache.org/jira/browse/IGNITE-4327 // Still, we only can convert from Object[] to something more precise. if (type == Value.ARRAY && currCls != expCls) { - if (currCls != Object[].class) + if (currCls != Object[].class) { throw new IgniteCheckedException("Unexpected array type - only conversion from Object[] " + "is assumed"); + } // Why would otherwise type be Value.ARRAY? assert expCls.isArray(); - Object[] curr = (Object[]) val; + Object[] curr = (Object[])val; Object newArr = Array.newInstance(expCls.getComponentType(), curr.length); @@ -104,11 +104,10 @@ public static Object convert(Object val, GridH2RowDescriptor desc, Class expC Object res = H2Utils.convert(val, desc.indexing(), type); - if (res instanceof Date && res.getClass() != Date.class && expCls == Date.class) { - // We can get a Timestamp instead of Date when converting a String to Date - // without query - let's handle this - return new Date(((Date) res).getTime()); - } + // We can get a Timestamp instead of Date when converting a String to Date + // without query - let's handle this + if (res instanceof Date && res.getClass() != Date.class && expCls == Date.class) + return new Date(((Date)res).getTime()); return res; } diff --git a/modules/indexing/src/test/java8/org/apache/ignite/internal/processors/query/h2/CacheQueryEntityWithJsr310Java8DateTimeApiFieldsTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/CacheQueryEntityWithDateTimeApiFieldsTest.java similarity index 72% rename from modules/indexing/src/test/java8/org/apache/ignite/internal/processors/query/h2/CacheQueryEntityWithJsr310Java8DateTimeApiFieldsTest.java rename to modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/CacheQueryEntityWithDateTimeApiFieldsTest.java index 6a144fcfc6089..d340b02be02f1 100644 --- a/modules/indexing/src/test/java8/org/apache/ignite/internal/processors/query/h2/CacheQueryEntityWithJsr310Java8DateTimeApiFieldsTest.java +++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/query/h2/CacheQueryEntityWithDateTimeApiFieldsTest.java @@ -28,188 +28,76 @@ import java.util.Objects; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheMode; +import org.apache.ignite.cache.CacheWriteSynchronizationMode; import org.apache.ignite.cache.query.SqlFieldsQuery; import org.apache.ignite.cache.query.annotations.QuerySqlField; import org.apache.ignite.configuration.CacheConfiguration; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; /** - * Tests queries against entities with JSR-310 Java 8 Date and Time API fields. + * Tests queries against entities with Java 8 Date and Time API fields. */ @RunWith(JUnit4.class) -public class CacheQueryEntityWithJsr310Java8DateTimeApiFieldsTest extends CacheQueryJsr310Java8DateTimeApiAbstractTest { +public class CacheQueryEntityWithDateTimeApiFieldsTest extends GridCommonAbstractTest { /** - * Entity containing JSR-310 fields. + * The number of days subtracted from the current time when constructing + * {@link LocalDate} and {@link LocalDateTime} + * instances. */ - private static class EntityWithJsr310Fields implements Serializable { + private static final long DAYS_BEFORE_NOW = 10; - /** Serial version UID. */ - private static final long serialVersionUID = 1L; - - /** ID. */ - @QuerySqlField(index = true) - private Long id; - - /** {@link LocalTime} field. */ - @QuerySqlField(index = true) - private LocalTime locTime; - - /** {@link LocalDate} field. */ - @QuerySqlField(index = true) - private LocalDate locDate; - - /** {@link LocalDateTime} field. */ - @QuerySqlField(index = true) - private LocalDateTime locDateTime; - - /** - * Default constructor. - */ - EntityWithJsr310Fields() { - } - - /** - * Copy constructor. - * - * @param entity Entity to copy from. - */ - EntityWithJsr310Fields(EntityWithJsr310Fields entity) { - id = entity.id; - locTime = LocalTime.from(entity.locTime); - locDate = LocalDate.from(entity.locDate); - locDateTime = LocalDateTime.from(entity.locDateTime); - } - - /** - * Constructor. - * - * @param id ID. - * @param locTime {@link LocalTime} value. - * @param locDate {@link LocalDate} value. - * @param locDateTime {@link LocalDateTime} value. - */ - EntityWithJsr310Fields(Long id, LocalTime locTime, LocalDate locDate, LocalDateTime locDateTime) { - this.id = id; - this.locTime = locTime; - this.locDate = locDate; - this.locDateTime = locDateTime; - } + /** {@link LocalTime} instance. */ + private static final LocalTime SAMPLE_TIME = LocalTime.now().minusHours(10); - /** - * Returns the ID. - * - * @return ID. - */ - public Long getId() { - return id; - } + /** {@link LocalDate} instance. */ + private static final LocalDate SAMPLE_DATE = LocalDate.now().minusDays(DAYS_BEFORE_NOW); - /** - * Sets the ID. - * - * @param id ID. - */ - public void setId(Long id) { - this.id = id; - } - - /** - * Returns the {@link LocalDateTime} field value - * - * @return {@link LocalDateTime} field value; - */ - public LocalDateTime getLocalDateTime() { - return locDateTime; - } + /** {@link LocalDateTime} instance. */ + private static final LocalDateTime SAMPLE_DATE_TIME = LocalDateTime.of(SAMPLE_DATE, LocalTime.MIDNIGHT); - /** - * Returns the {@link LocalDateTime} field value. - * - * @param locDateTime {@link LocalDateTime} value. - */ - public void setLocalDateTime(LocalDateTime locDateTime) { - this.locDateTime = locDateTime; - } - - /** - * Returns the {@link LocalDate} field value. - * - * @return {@link LocalDate} field value. - */ - public LocalDate getLocalDate() { - return locDate; - } - - /** - * Sets the {@link LocalDate} field value. - * - * @param locDate {@link LocalDate} value. - */ - public void setLocalDate(LocalDate locDate) { - this.locDate = locDate; - } - - /** - * Returns the {@link LocalTime} field value. - * - * @return {@link LocalTime} field value. - */ - public LocalTime getLocalTime() { - return locTime; - } - - /** - * Sets the {@link LocalTime} field value. - * - * @param locTime {@link LocalTime} value. - */ - public void setLocalTime(LocalTime locTime) { - this.locTime = locTime; - } - - /** {@inheritDoc} */ - @Override public boolean equals(Object o) { - if (this == o) - return true; - - if (o == null || getClass() != o.getClass()) - return false; - - EntityWithJsr310Fields fields = (EntityWithJsr310Fields)o; - - return Objects.equals(id, fields.id) && Objects.equals(locDateTime, fields.locDateTime) && - Objects.equals(locDate, fields.locDate) && Objects.equals(locTime, fields.locTime); - } + /** Cache. */ + private IgniteCache cache; - /** {@inheritDoc} */ - @Override public int hashCode() { - return Objects.hash(id, locDateTime, locDate, locTime); - } + /** Entity with Date and Time fields instance. */ + private final EntityWithDateTimeFields entity = + new EntityWithDateTimeFields(1L, SAMPLE_TIME, SAMPLE_DATE, SAMPLE_DATE_TIME); - /** {@inheritDoc} */ - @Override public String toString() { - return "EntityWithJsr310Fields{" + "id=" + id + ", locDateTime=" + locDateTime + ", locDate=" + locDate + - ", locTime=" + locTime + '}'; - } + /** + * Creates a cache configuration with the specified cache name + * and indexed type key/value pairs. + * + * @param cacheName Cache name + * @param indexedTypes key/value pairs according to {@link CacheConfiguration#setIndexedTypes(Class[])}. + * @param Key type. + * @param Value type. + * @return Cache configuration. + */ + protected static CacheConfiguration createCacheConfig(String cacheName, Class... indexedTypes) { + return new CacheConfiguration(cacheName) + .setCacheMode(CacheMode.REPLICATED) + .setAtomicityMode(CacheAtomicityMode.ATOMIC) + .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC) + .setIndexedTypes(indexedTypes); } - /** Cache. */ - private IgniteCache cache; - - /** Entity with JSR-310 fields instance. */ - private final EntityWithJsr310Fields entity = - new EntityWithJsr310Fields(1L, LOCAL_TIME, LOCAL_DATE, LOCAL_DATE_TIME); + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } /** * Creates a cache configuration. * * @return Cache configuration. */ - private static CacheConfiguration createCacheConfig() { + private static CacheConfiguration createCacheConfig() { return createCacheConfig( - "entityWithJava8DataTimeFields", Long.class, EntityWithJsr310Fields.class + "entityWithJava8DataTimeFields", Long.class, EntityWithDateTimeFields.class ); } @@ -233,7 +121,7 @@ public void testInsertEntityFields() throws Exception { assertEquals(0, cache.size()); SqlFieldsQuery qry = new SqlFieldsQuery( - "insert into EntityWithJsr310Fields(_key, id, locTime, locDate, locDateTime) values(?, ?, ?, ?, ?)" + "insert into EntityWithDateTimeFields(_key, id, locTime, locDate, locDateTime) values(?, ?, ?, ?, ?)" ).setArgs( entity.getId(), entity.getId(), entity.getLocalTime(), entity.getLocalDate(), entity.getLocalDateTime() ); @@ -255,7 +143,7 @@ public void testInsertEntityFields() throws Exception { @Test public void testDateDiffForLocalDateTimeFieldAtMidnight() throws Exception { SqlFieldsQuery qry = - new SqlFieldsQuery("select DATEDIFF('DAY', locDateTime, CURRENT_DATE ()) from EntityWithJsr310Fields"); + new SqlFieldsQuery("select DATEDIFF('DAY', locDateTime, CURRENT_DATE ()) from EntityWithDateTimeFields"); List> qryResults = cache.query(qry).getAll(); @@ -270,7 +158,7 @@ public void testDateDiffForLocalDateTimeFieldAtMidnight() throws Exception { */ @Test public void testSelectLocalTimeFieldReturnsTime() throws Exception { - SqlFieldsQuery qry = new SqlFieldsQuery("select locTime from EntityWithJsr310Fields"); + SqlFieldsQuery qry = new SqlFieldsQuery("select locTime from EntityWithDateTimeFields"); List> qryResults = cache.query(qry).getAll(); @@ -285,7 +173,7 @@ public void testSelectLocalTimeFieldReturnsTime() throws Exception { */ @Test public void testSelectLocalDateFieldReturnsDate() throws Exception { - SqlFieldsQuery qry = new SqlFieldsQuery("select locDate from EntityWithJsr310Fields"); + SqlFieldsQuery qry = new SqlFieldsQuery("select locDate from EntityWithDateTimeFields"); List> qryResults = cache.query(qry).getAll(); @@ -300,7 +188,7 @@ public void testSelectLocalDateFieldReturnsDate() throws Exception { */ @Test public void testSelectLocalDateTimeFieldReturnsTimestamp() throws Exception { - SqlFieldsQuery qry = new SqlFieldsQuery("select locDateTime from EntityWithJsr310Fields"); + SqlFieldsQuery qry = new SqlFieldsQuery("select locDateTime from EntityWithDateTimeFields"); List> qryResults = cache.query(qry).getAll(); @@ -312,9 +200,9 @@ public void testSelectLocalDateTimeFieldReturnsTimestamp() throws Exception { * Tests selection of an entity by a {@link LocalTime} field. */ @Test - public void testSelectByAllJsr310Fields() { + public void testSelectByAllFields() { SqlFieldsQuery qry = new SqlFieldsQuery( - "select locDate from EntityWithJsr310Fields where locTime = ? and locDate = ? and locDateTime = ?" + "select locDate from EntityWithDateTimeFields where locTime = ? and locDate = ? and locDateTime = ?" ).setArgs(entity.getLocalTime(), entity.getLocalDate(), entity.getLocalDateTime()); List> qryResults = cache.query(qry).getAll(); @@ -324,18 +212,18 @@ public void testSelectByAllJsr310Fields() { } /** - * Tests updating of all JSR-310 fields. + * Tests updating of all Date and Time fields. */ @Test - public void testUpdateAllJsr310Fields() { - EntityWithJsr310Fields expEntity = new EntityWithJsr310Fields(entity); + public void testUpdateAllFields() { + EntityWithDateTimeFields expEntity = new EntityWithDateTimeFields(entity); expEntity.setLocalTime(expEntity.getLocalTime().plusHours(1)); expEntity.setLocalDate(expEntity.getLocalDate().plusDays(1)); expEntity.setLocalDateTime(LocalDateTime.of(expEntity.getLocalDate(), expEntity.getLocalTime())); SqlFieldsQuery qry = new SqlFieldsQuery( - "update EntityWithJsr310Fields set locTime = ?, locDate = ?, locDateTime = ? where id = ?" + "update EntityWithDateTimeFields set locTime = ?, locDate = ?, locDateTime = ? where id = ?" ).setArgs(expEntity.getLocalTime(), expEntity.getLocalDate(), expEntity.getLocalDateTime(), entity.getId()); List> qryResults = cache.query(qry).getAll(); @@ -346,12 +234,12 @@ public void testUpdateAllJsr310Fields() { } /** - * Tests deleting by all JSR-310 fields. + * Tests deleting by all Date and Time fields. */ @Test - public void testDeleteByAllJsr310Fields() { + public void testDeleteByAllFields() { SqlFieldsQuery qry = new SqlFieldsQuery( - "delete from EntityWithJsr310Fields where locTime = ? and locDate = ? and locDateTime = ?" + "delete from EntityWithDateTimeFields where locTime = ? and locDate = ? and locDateTime = ?" ).setArgs(entity.getLocalTime(), entity.getLocalDate(), entity.getLocalDateTime()); List> qryResults = cache.query(qry).getAll(); @@ -360,4 +248,158 @@ public void testDeleteByAllJsr310Fields() { assertEquals(1L, qryResults.get(0).get(0)); assertEquals(0, cache.size()); } + + /** + * Entity containing Java 8 Date and Time fields. + */ + private static class EntityWithDateTimeFields implements Serializable { + /** Serial version UID. */ + private static final long serialVersionUID = 1L; + + /** ID. */ + @QuerySqlField(index = true) + private Long id; + + /** {@link LocalTime} field. */ + @QuerySqlField(index = true) + private LocalTime locTime; + + /** {@link LocalDate} field. */ + @QuerySqlField(index = true) + private LocalDate locDate; + + /** {@link LocalDateTime} field. */ + @QuerySqlField(index = true) + private LocalDateTime locDateTime; + + /** + * Default constructor. + */ + EntityWithDateTimeFields() { + } + + /** + * Copy constructor. + * + * @param entity Entity to copy from. + */ + EntityWithDateTimeFields(EntityWithDateTimeFields entity) { + id = entity.id; + locTime = LocalTime.from(entity.locTime); + locDate = LocalDate.from(entity.locDate); + locDateTime = LocalDateTime.from(entity.locDateTime); + } + + /** + * Constructor. + * + * @param id ID. + * @param locTime {@link LocalTime} value. + * @param locDate {@link LocalDate} value. + * @param locDateTime {@link LocalDateTime} value. + */ + EntityWithDateTimeFields(Long id, LocalTime locTime, LocalDate locDate, LocalDateTime locDateTime) { + this.id = id; + this.locTime = locTime; + this.locDate = locDate; + this.locDateTime = locDateTime; + } + + /** + * Returns the ID. + * + * @return ID. + */ + public Long getId() { + return id; + } + + /** + * Sets the ID. + * + * @param id ID. + */ + public void setId(Long id) { + this.id = id; + } + + /** + * Returns the {@link LocalDateTime} field value + * + * @return {@link LocalDateTime} field value; + */ + public LocalDateTime getLocalDateTime() { + return locDateTime; + } + + /** + * Returns the {@link LocalDateTime} field value. + * + * @param locDateTime {@link LocalDateTime} value. + */ + public void setLocalDateTime(LocalDateTime locDateTime) { + this.locDateTime = locDateTime; + } + + /** + * Returns the {@link LocalDate} field value. + * + * @return {@link LocalDate} field value. + */ + public LocalDate getLocalDate() { + return locDate; + } + + /** + * Sets the {@link LocalDate} field value. + * + * @param locDate {@link LocalDate} value. + */ + public void setLocalDate(LocalDate locDate) { + this.locDate = locDate; + } + + /** + * Returns the {@link LocalTime} field value. + * + * @return {@link LocalTime} field value. + */ + public LocalTime getLocalTime() { + return locTime; + } + + /** + * Sets the {@link LocalTime} field value. + * + * @param locTime {@link LocalTime} value. + */ + public void setLocalTime(LocalTime locTime) { + this.locTime = locTime; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object o) { + if (this == o) + return true; + + if (o == null || getClass() != o.getClass()) + return false; + + EntityWithDateTimeFields fields = (EntityWithDateTimeFields)o; + + return Objects.equals(id, fields.id) && Objects.equals(locDateTime, fields.locDateTime) && + Objects.equals(locDate, fields.locDate) && Objects.equals(locTime, fields.locTime); + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return Objects.hash(id, locDateTime, locDate, locTime); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return "EntityWithDateTimeFields{" + "id=" + id + ", locDateTime=" + locDateTime + ", locDate=" + locDate + + ", locTime=" + locTime + '}'; + } + } } diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite2.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite2.java index cd58c1af8a2c5..e4c918ee832c0 100644 --- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite2.java +++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite2.java @@ -52,6 +52,7 @@ import org.apache.ignite.internal.processors.query.IgniteCacheGroupsSqlDistributedJoinSelfTest; import org.apache.ignite.internal.processors.query.IgniteCacheGroupsSqlSegmentedIndexMultiNodeSelfTest; import org.apache.ignite.internal.processors.query.IgniteCacheGroupsSqlSegmentedIndexSelfTest; +import org.apache.ignite.internal.processors.query.h2.CacheQueryEntityWithDateTimeApiFieldsTest; import org.apache.ignite.internal.processors.query.h2.twostep.CacheQueryMemoryLeakTest; import org.apache.ignite.internal.processors.query.h2.twostep.CreateTableWithDateKeySelfTest; import org.apache.ignite.internal.processors.query.h2.twostep.DisappearedCacheCauseRetryMessageSelfTest; @@ -122,6 +123,8 @@ public static TestSuite suite() { suite.addTest(new JUnit4TestAdapter(CreateTableWithDateKeySelfTest.class)); + suite.addTest(new JUnit4TestAdapter(CacheQueryEntityWithDateTimeApiFieldsTest.class)); + suite.addTest(new JUnit4TestAdapter(NonCollocatedRetryMessageSelfTest.class)); suite.addTest(new JUnit4TestAdapter(RetryCauseMessageSelfTest.class)); suite.addTest(new JUnit4TestAdapter(DisappearedCacheCauseRetryMessageSelfTest.class)); diff --git a/modules/indexing/src/test/java8/org/apache/ignite/internal/processors/query/h2/CacheQueryJsr310Java8DateTimeApiAbstractTest.java b/modules/indexing/src/test/java8/org/apache/ignite/internal/processors/query/h2/CacheQueryJsr310Java8DateTimeApiAbstractTest.java deleted file mode 100644 index 61c5d1d3eea35..0000000000000 --- a/modules/indexing/src/test/java8/org/apache/ignite/internal/processors/query/h2/CacheQueryJsr310Java8DateTimeApiAbstractTest.java +++ /dev/null @@ -1,72 +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.ignite.internal.processors.query.h2; - -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.LocalTime; -import org.apache.ignite.cache.CacheAtomicityMode; -import org.apache.ignite.cache.CacheMode; -import org.apache.ignite.cache.CacheWriteSynchronizationMode; -import org.apache.ignite.configuration.CacheConfiguration; -import org.apache.ignite.configuration.IgniteConfiguration; -import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; - -/** - * Base class for JSR-310 Java 8 Date and Time API queries tests. - */ -public abstract class CacheQueryJsr310Java8DateTimeApiAbstractTest extends GridCommonAbstractTest { - /** {@link LocalTime} instance. */ - protected static final LocalTime LOCAL_TIME = LocalTime.now().minusHours(10); - - /** - * The number of days subtracted from the current time when constructing - * {@link LocalDate} and {@link LocalDateTime} - * instances. - */ - protected static final long DAYS_BEFORE_NOW = 10; - - /** {@link LocalDate} instance. */ - protected static final LocalDate LOCAL_DATE = LocalDate.now().minusDays(DAYS_BEFORE_NOW); - - /** {@link LocalDateTime} instance. */ - protected static final LocalDateTime LOCAL_DATE_TIME = LocalDateTime.of(LOCAL_DATE, LocalTime.MIDNIGHT); - - /** - * Creates a cache configuration with the specified cache name - * and indexed type key/value pairs. - * - * @param cacheName Cache name - * @param indexedTypes key/value pairs according to {@link CacheConfiguration#setIndexedTypes(Class[])}. - * @param Key type. - * @param Value type. - * @return Cache configuration. - */ - protected static CacheConfiguration createCacheConfig(String cacheName, Class... indexedTypes) { - return new CacheConfiguration(cacheName) - .setCacheMode(CacheMode.REPLICATED) - .setAtomicityMode(CacheAtomicityMode.ATOMIC) - .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC) - .setIndexedTypes(indexedTypes); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - stopAllGrids(); - } -} diff --git a/modules/indexing/src/test/java8/org/apache/ignite/testsuites/CacheQueryJsr310Java8DateTimeApiSupportTestSuite.java b/modules/indexing/src/test/java8/org/apache/ignite/testsuites/CacheQueryJsr310Java8DateTimeApiSupportTestSuite.java deleted file mode 100644 index 7999218dc1ed6..0000000000000 --- a/modules/indexing/src/test/java8/org/apache/ignite/testsuites/CacheQueryJsr310Java8DateTimeApiSupportTestSuite.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.ignite.testsuites; - -import junit.framework.JUnit4TestAdapter; -import junit.framework.TestSuite; -import org.apache.ignite.internal.processors.query.h2.CacheQueryEntityWithJsr310Java8DateTimeApiFieldsTest; -import org.junit.runner.RunWith; -import org.junit.runners.AllTests; - -/** - * Test suite for JSR-310 Java 8 Date and Time API queries. - */ -@RunWith(AllTests.class) -public class CacheQueryJsr310Java8DateTimeApiSupportTestSuite { - /** - * @return Test suite. - * @throws Exception If failed. - */ - public static TestSuite suite() throws Exception { - TestSuite suite = new TestSuite("JSR-310 Java 8 Date and Time API Cache Queries Test Suite"); - - suite.addTest(new JUnit4TestAdapter(CacheQueryEntityWithJsr310Java8DateTimeApiFieldsTest.class)); - - return suite; - } -}