DATAREDIS-595 - Integrate DATACMNS Java 8 upgrade.

Integrate DATACMNS-867 and DATAKV-159 branches.
This commit is contained in:
Christoph Strobl
2017-01-24 13:16:50 +01:00
parent d0e52dd9f0
commit 00b4009553
21 changed files with 316 additions and 330 deletions

View File

@@ -25,6 +25,7 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.junit.After;
import org.junit.AfterClass;
@@ -221,7 +222,7 @@ public class RedisKeyValueTemplateTests {
template.insert(update);
assertThat(template.findById(rand.id, Person.class), is(equalTo(new Person(rand.id, "rand", "al-thor"))));
assertThat(template.findById(rand.id, Person.class), is(equalTo(Optional.of(new Person(rand.id, "rand", "al-thor")))));
nativeTemplate.execute(new RedisCallback<Void>() {
@Override
@@ -243,7 +244,7 @@ public class RedisKeyValueTemplateTests {
template.update(update);
assertThat(template.findById(rand.id, Person.class), is(equalTo(new Person(rand.id, "frodo", "al-thor"))));
assertThat(template.findById(rand.id, Person.class), is(equalTo(Optional.of(new Person(rand.id, "frodo", "al-thor")))));
nativeTemplate.execute(new RedisCallback<Void>() {
@Override
@@ -264,7 +265,7 @@ public class RedisKeyValueTemplateTests {
template.doPartialUpdate(update);
assertThat(template.findById(rand.id, Person.class), is(equalTo(new Person(rand.id, null, "baggins"))));
assertThat(template.findById(rand.id, Person.class), is(equalTo(Optional.of(new Person(rand.id, null, "baggins")))));
nativeTemplate.execute(new RedisCallback<Void>() {
@Override
@@ -286,7 +287,7 @@ public class RedisKeyValueTemplateTests {
template.doPartialUpdate(update);
assertThat(template.findById(rand.id, Person.class), is(equalTo(new Person(rand.id, null, null))));
assertThat(template.findById(rand.id, Person.class), is(equalTo(Optional.of(new Person(rand.id, null, null)))));
nativeTemplate.execute(new RedisCallback<Void>() {
@Override
@@ -834,9 +835,9 @@ public class RedisKeyValueTemplateTests {
Thread.sleep(1100);
WithTtl target = template.findById(source.id, WithTtl.class);
assertThat(target.ttl, is(notNullValue()));
assertThat(target.ttl.doubleValue(), is(closeTo(3D, 1D)));
Optional<WithTtl> target = template.findById(source.id, WithTtl.class);
assertThat(target.get().ttl, is(notNullValue()));
assertThat(target.get().ttl.doubleValue(), is(closeTo(3D, 1D)));
}
@Test // DATAREDIS-523
@@ -851,8 +852,8 @@ public class RedisKeyValueTemplateTests {
Thread.sleep(1100);
WithPrimitiveTtl target = template.findById(source.id, WithPrimitiveTtl.class);
assertThat((double) target.ttl, is(closeTo(3D, 1D)));
Optional<WithPrimitiveTtl> target = template.findById(source.id, WithPrimitiveTtl.class);
assertThat((double) target.get().ttl, is(closeTo(3D, 1D)));
}
@Test // DATAREDIS-523
@@ -891,8 +892,8 @@ public class RedisKeyValueTemplateTests {
}
});
WithTtl target = template.findById(source.id, WithTtl.class);
assertThat(target.ttl, is(-1L));
Optional<WithTtl> target = template.findById(source.id, WithTtl.class);
assertThat(target.get().ttl, is(-1L));
}
@EqualsAndHashCode

View File

@@ -1237,6 +1237,7 @@ public class MappingRedisConverterUnitTests {
di.object = "foo";
RedisData rd = write(di);
System.out.println(rd.getBucket().toString());
TypeWithObjectValueTypes result = converter.read(TypeWithObjectValueTypes.class, rd);
assertThat(result.object, instanceOf(String.class));

View File

@@ -29,6 +29,7 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.hamcrest.core.IsCollectionContaining;
@@ -253,7 +254,7 @@ public class PathIndexResolverUnitTests {
public void resolveIndexShouldReturnDataWhenNoIndexConfiguredButPropertyAnnotated() {
when(propertyMock.isAnnotationPresent(eq(Indexed.class))).thenReturn(true);
when(propertyMock.findAnnotation(eq(Indexed.class))).thenReturn(createIndexedInstance());
when(propertyMock.findAnnotation(eq(Indexed.class))).thenReturn(Optional.of(createIndexedInstance()));
assertThat(resolve("foo", "rand"), notNullValue());
}
@@ -263,7 +264,7 @@ public class PathIndexResolverUnitTests {
when(propertyMock.isCollectionLike()).thenReturn(true);
when(propertyMock.isAnnotationPresent(eq(Indexed.class))).thenReturn(true);
when(propertyMock.findAnnotation(eq(Indexed.class))).thenReturn(createIndexedInstance());
when(propertyMock.findAnnotation(eq(Indexed.class))).thenReturn(Optional.of(createIndexedInstance()));
IndexedData index = resolve("list.[0].name", "rand");
@@ -275,7 +276,7 @@ public class PathIndexResolverUnitTests {
when(propertyMock.isMap()).thenReturn(true);
when(propertyMock.isAnnotationPresent(eq(Indexed.class))).thenReturn(true);
when(propertyMock.findAnnotation(eq(Indexed.class))).thenReturn(createIndexedInstance());
when(propertyMock.findAnnotation(eq(Indexed.class))).thenReturn(Optional.of(createIndexedInstance()));
IndexedData index = resolve("map.[foo].name", "rand");
@@ -287,7 +288,7 @@ public class PathIndexResolverUnitTests {
when(propertyMock.isMap()).thenReturn(true);
when(propertyMock.isAnnotationPresent(eq(Indexed.class))).thenReturn(true);
when(propertyMock.findAnnotation(eq(Indexed.class))).thenReturn(createIndexedInstance());
when(propertyMock.findAnnotation(eq(Indexed.class))).thenReturn(Optional.of(createIndexedInstance()));
IndexedData index = resolve("map.[0].name", "rand");
@@ -449,7 +450,7 @@ public class PathIndexResolverUnitTests {
when(propertyMock.isMap()).thenReturn(true);
when(propertyMock.isAnnotationPresent(eq(GeoIndexed.class))).thenReturn(true);
when(propertyMock.findAnnotation(eq(GeoIndexed.class))).thenReturn(createGeoIndexedInstance());
when(propertyMock.findAnnotation(eq(GeoIndexed.class))).thenReturn(Optional.of(createGeoIndexedInstance()));
IndexedData index = resolve("location", new Point(1D, 2D));
@@ -461,7 +462,7 @@ public class PathIndexResolverUnitTests {
when(propertyMock.isMap()).thenReturn(true);
when(propertyMock.isAnnotationPresent(eq(GeoIndexed.class))).thenReturn(true);
when(propertyMock.findAnnotation(eq(GeoIndexed.class))).thenReturn(createGeoIndexedInstance());
when(propertyMock.findAnnotation(eq(GeoIndexed.class))).thenReturn(Optional.of(createGeoIndexedInstance()));
IndexedData index = resolve("property.location", new Point(1D, 2D));

View File

@@ -24,11 +24,11 @@ import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentEntity;
import org.springframework.data.redis.core.convert.KeyspaceConfiguration.KeyspaceSettings;
import org.springframework.data.redis.core.index.IndexConfiguration;
import org.springframework.data.redis.core.index.SpelIndexDefinition;
import org.springframework.data.redis.core.mapping.RedisMappingContext;
import org.springframework.data.redis.core.mapping.RedisPersistentEntity;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.expression.AccessException;
import org.springframework.expression.BeanResolver;
@@ -57,7 +57,7 @@ public class SpelIndexResolverUnitTests {
RedisMappingContext mappingContext;
KeyValuePersistentEntity<?> entity;
RedisPersistentEntity<?> entity;
@Before
public void setup() {

View File

@@ -22,6 +22,7 @@ import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
import java.io.Serializable;
import java.util.Optional;
import org.junit.Before;
import org.junit.Rule;
@@ -31,7 +32,6 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.data.keyvalue.core.mapping.KeySpaceResolver;
import org.springframework.data.keyvalue.core.mapping.KeyValuePersistentProperty;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.redis.core.TimeToLiveAccessor;
import org.springframework.data.redis.core.convert.ConversionTestEntities;
@@ -68,10 +68,10 @@ public class BasicRedisPersistentEntityUnitTests<T, ID extends Serializable> {
expectedException.expectMessage("Attempt to add id property");
expectedException.expectMessage("but already have an property");
KeyValuePersistentProperty property1 = mock(RedisPersistentProperty.class);
RedisPersistentProperty property1 = mock(RedisPersistentProperty.class);
when(property1.isIdProperty()).thenReturn(true);
KeyValuePersistentProperty property2 = mock(RedisPersistentProperty.class);
RedisPersistentProperty property2 = mock(RedisPersistentProperty.class);
when(property2.isIdProperty()).thenReturn(true);
entity.addPersistentProperty(property1);
@@ -86,11 +86,11 @@ public class BasicRedisPersistentEntityUnitTests<T, ID extends Serializable> {
expectedException.expectMessage("Attempt to add explicit id property");
expectedException.expectMessage("but already have an property");
KeyValuePersistentProperty property1 = mock(RedisPersistentProperty.class);
RedisPersistentProperty property1 = mock(RedisPersistentProperty.class);
when(property1.isIdProperty()).thenReturn(true);
when(property1.isAnnotationPresent(any(Class.class))).thenReturn(true);
KeyValuePersistentProperty property2 = mock(RedisPersistentProperty.class);
RedisPersistentProperty property2 = mock(RedisPersistentProperty.class);
when(property2.isIdProperty()).thenReturn(true);
when(property2.isAnnotationPresent(any(Class.class))).thenReturn(true);
@@ -102,16 +102,16 @@ public class BasicRedisPersistentEntityUnitTests<T, ID extends Serializable> {
@SuppressWarnings("unchecked")
public void explicitIdPropertiyShouldBeFavoredOverNonExplicit() {
KeyValuePersistentProperty property1 = mock(RedisPersistentProperty.class);
RedisPersistentProperty property1 = mock(RedisPersistentProperty.class);
when(property1.isIdProperty()).thenReturn(true);
KeyValuePersistentProperty property2 = mock(RedisPersistentProperty.class);
RedisPersistentProperty property2 = mock(RedisPersistentProperty.class);
when(property2.isIdProperty()).thenReturn(true);
when(property2.isAnnotationPresent(any(Class.class))).thenReturn(true);
entity.addPersistentProperty(property1);
entity.addPersistentProperty(property2);
assertThat(entity.getIdProperty(), is(equalTo(property2)));
assertThat(entity.getIdProperty(), is(equalTo(Optional.of(property2))));
}
}

View File

@@ -22,6 +22,7 @@ import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.hamcrest.core.IsNull;
import org.junit.Before;
@@ -80,8 +81,8 @@ public abstract class RedisRepositoryIntegrationTestBase {
assertThat(repo.count(), is(2L));
assertThat(repo.findOne(rand.id), is(rand));
assertThat(repo.findOne(egwene.id), is(egwene));
assertThat(repo.findOne(rand.id), is(Optional.of(rand)));
assertThat(repo.findOne(egwene.id), is(Optional.of(egwene)));
assertThat(repo.findByFirstname("rand").size(), is(1));
assertThat(repo.findByFirstname("rand"), hasItem(rand));
@@ -130,15 +131,15 @@ public abstract class RedisRepositoryIntegrationTestBase {
repo.save(moiraine);
// find and assert current location set correctly
Person loaded = repo.findOne(moiraine.getId());
assertThat(loaded.city, is(tarValon));
Optional<Person> loaded = repo.findOne(moiraine.getId());
assertThat(loaded.get().city, is(tarValon));
// remove reference location data
kvTemplate.delete("1", City.class);
// find and assert the location is gone
Person reLoaded = repo.findOne(moiraine.getId());
assertThat(reLoaded.city, IsNull.nullValue());
Optional<Person> reLoaded = repo.findOne(moiraine.getId());
assertThat(reLoaded.get().city, IsNull.nullValue());
}
@Test // DATAREDIS-425