re-enable tests
This commit is contained in:
parent
12fb58f6b9
commit
cc105596b4
|
@ -9,6 +9,7 @@ package org.hibernate;
|
|||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.CONSTRUCTOR;
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.ElementType.PACKAGE;
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
|
@ -21,7 +22,7 @@ import static java.lang.annotation.RetentionPolicy.CLASS;
|
|||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
@Target({PACKAGE, TYPE, METHOD})
|
||||
@Target({PACKAGE, TYPE, METHOD, CONSTRUCTOR})
|
||||
@Retention(CLASS)
|
||||
public @interface Internal {
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ package org.hibernate.cache.internal;
|
|||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.hibernate.Internal;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
|
@ -22,7 +23,8 @@ import org.hibernate.type.Type;
|
|||
* @author Gavin King
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
final class CacheKeyImplementation implements Serializable {
|
||||
@Internal
|
||||
public final class CacheKeyImplementation implements Serializable {
|
||||
private final Object id;
|
||||
private final Type type;
|
||||
private final String entityOrRoleName;
|
||||
|
@ -40,7 +42,8 @@ final class CacheKeyImplementation implements Serializable {
|
|||
* @param tenantId The tenant identifier associated with this data.
|
||||
* @param factory The session factory for which we are caching
|
||||
*/
|
||||
CacheKeyImplementation(
|
||||
@Internal
|
||||
public CacheKeyImplementation(
|
||||
final Object id,
|
||||
final Type type,
|
||||
final String entityOrRoleName,
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.cache.spi;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import org.hibernate.cache.internal.DefaultCacheKeysFactory;
|
||||
import org.hibernate.cache.internal.NaturalIdCacheKey;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.type.Type;
|
||||
import org.junit.Test;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.mockito.Matchers.anyObject;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class NaturalIdCacheKeyTest {
|
||||
@Test
|
||||
public void testSerializationRoundTrip() throws Exception {
|
||||
final EntityPersister entityPersister = mock(EntityPersister.class);
|
||||
final SessionImplementor sessionImplementor = mock(SessionImplementor.class);
|
||||
final SessionFactoryImplementor sessionFactoryImplementor = mock(SessionFactoryImplementor.class);
|
||||
final Type mockType = mock(Type.class);
|
||||
|
||||
when (entityPersister.getRootEntityName()).thenReturn("EntityName");
|
||||
|
||||
when(sessionImplementor.getFactory()).thenReturn(sessionFactoryImplementor);
|
||||
|
||||
when(entityPersister.getNaturalIdentifierProperties()).thenReturn(new int[] {0, 1, 2});
|
||||
when(entityPersister.getPropertyTypes()).thenReturn(new Type[] {
|
||||
mockType,
|
||||
mockType,
|
||||
mockType
|
||||
});
|
||||
|
||||
when(mockType.getHashCode(anyObject(), eq(sessionFactoryImplementor))).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return invocation.getArguments()[0].hashCode();
|
||||
}
|
||||
});
|
||||
|
||||
when(mockType.disassemble(anyObject(), eq(sessionImplementor), eq(null))).thenAnswer(new Answer<Object>() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
return invocation.getArguments()[0];
|
||||
}
|
||||
});
|
||||
|
||||
final NaturalIdCacheKey key = (NaturalIdCacheKey) DefaultCacheKeysFactory.staticCreateNaturalIdKey( new Object[] {"a", "b", "c"}, entityPersister, sessionImplementor );
|
||||
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(key);
|
||||
|
||||
final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
|
||||
final NaturalIdCacheKey keyClone = (NaturalIdCacheKey) ois.readObject();
|
||||
|
||||
assertEquals(key, keyClone);
|
||||
assertEquals(key.hashCode(), keyClone.hashCode());
|
||||
assertEquals(key.toString(), keyClone.toString());
|
||||
assertEquals(key.getEntityName(), keyClone.getEntityName());
|
||||
assertEquals(key.getNaturalIdValues(), keyClone.getNaturalIdValues());
|
||||
assertEquals(key.getTenantId(), keyClone.getTenantId());
|
||||
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.cache.spi;
|
||||
package org.hibernate.orm.test.caching.mocked;
|
||||
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.cache.internal;
|
||||
package org.hibernate.orm.test.caching.mocked;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
|
@ -16,6 +16,7 @@ import org.hibernate.boot.Metadata;
|
|||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.SessionFactoryBuilder;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cache.internal.CacheKeyImplementation;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.orm.test.caching.mocked;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
|
||||
import org.hibernate.cache.internal.DefaultCacheKeysFactory;
|
||||
import org.hibernate.cache.internal.NaturalIdCacheKey;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.metamodel.RuntimeMetamodels;
|
||||
import org.hibernate.metamodel.mapping.NaturalIdMapping;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class NaturalIdCacheKeyTest {
|
||||
@Test
|
||||
public void testSerializationRoundTrip() throws Exception {
|
||||
final SessionFactoryImplementor sessionFactoryImplementor = mock( SessionFactoryImplementor.class );
|
||||
final SessionImplementor sessionImplementor = mock( SessionImplementor.class );
|
||||
|
||||
final RuntimeMetamodels runtimeMetamodels = mock( RuntimeMetamodels.class );
|
||||
final EntityPersister entityPersister = mock( EntityPersister.class );
|
||||
final NaturalIdMapping naturalIdMapping = mock( NaturalIdMapping.class );
|
||||
|
||||
when( sessionImplementor.getFactory() ).thenReturn( sessionFactoryImplementor );
|
||||
when( sessionFactoryImplementor.getRuntimeMetamodels()).thenReturn( runtimeMetamodels );
|
||||
when( runtimeMetamodels.getEntityMappingType( anyString() ) ).thenReturn( entityPersister );
|
||||
when( entityPersister.getRootEntityName() ).thenReturn( "EntityName" );
|
||||
when( entityPersister.getNaturalIdMapping() ).thenReturn( naturalIdMapping );
|
||||
when( naturalIdMapping.disassemble( any(), eq( sessionImplementor ) ) ).thenAnswer( invocation -> invocation.getArguments()[0] );
|
||||
when( naturalIdMapping.calculateHashCode( any(), eq( sessionImplementor ) ) ).thenAnswer( invocation -> invocation.getArguments()[0].hashCode() );
|
||||
|
||||
|
||||
final NaturalIdCacheKey key = (NaturalIdCacheKey) DefaultCacheKeysFactory.staticCreateNaturalIdKey( new Object[] {"a", "b", "c"}, entityPersister, sessionImplementor );
|
||||
|
||||
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(key);
|
||||
|
||||
final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
|
||||
final NaturalIdCacheKey keyClone = (NaturalIdCacheKey) ois.readObject();
|
||||
|
||||
assertEquals(key, keyClone);
|
||||
assertEquals(key.hashCode(), keyClone.hashCode());
|
||||
assertEquals(key.toString(), keyClone.toString());
|
||||
assertEquals(key.getEntityName(), keyClone.getEntityName());
|
||||
assertArrayEquals( (Object[]) key.getNaturalIdValues(), (Object[]) keyClone.getNaturalIdValues() );
|
||||
assertEquals(key.getTenantId(), keyClone.getTenantId());
|
||||
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.cache.spi;
|
||||
package org.hibernate.orm.test.caching.mocked;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
|
||||
/**
|
||||
* Simple mock-driven tests for key and access contracts related to caching
|
||||
*/
|
||||
package org.hibernate.orm.test.caching.mocked;
|
Loading…
Reference in New Issue