use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class DataRowStoreIT method testMaxSize.
/**
* Tests LRU cache behavior.
*/
@Test
public void testMaxSize() throws Exception {
Map<String, String> props = new HashMap<>();
props.put(Constants.SNAPSHOT_CACHE_SIZE_PROPERTY, String.valueOf(2));
cache = new DataRowStore("cacheXYZ", new DefaultRuntimeProperties(props), null);
assertEquals(2, cache.maximumSize());
assertEquals(0, cache.size());
ObjectId key1 = new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, 1);
Map<ObjectId, DataRow> diff1 = new HashMap<>();
diff1.put(key1, new DataRow(1));
ObjectId key2 = new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, 2);
Map<ObjectId, DataRow> diff2 = new HashMap<>();
diff2.put(key2, new DataRow(1));
ObjectId key3 = new ObjectId("Artist", Artist.ARTIST_ID_PK_COLUMN, 3);
Map<ObjectId, DataRow> diff3 = new HashMap<>();
diff3.put(key3, new DataRow(1));
cache.processSnapshotChanges(this, diff1, Collections.<ObjectId>emptyList(), Collections.<ObjectId>emptyList(), Collections.<ObjectId>emptyList());
assertEquals(1, cache.size());
cache.processSnapshotChanges(this, diff2, Collections.<ObjectId>emptyList(), Collections.<ObjectId>emptyList(), Collections.<ObjectId>emptyList());
assertEquals(2, cache.size());
// this addition must overflow the cache, and throw out the first item
cache.processSnapshotChanges(this, diff3, Collections.<ObjectId>emptyList(), Collections.<ObjectId>emptyList(), Collections.<ObjectId>emptyList());
assertEquals(2, cache.size());
assertNotNull(cache.getCachedSnapshot(key2));
assertNotNull(cache.getCachedSnapshot(key3));
assertNull(cache.getCachedSnapshot(key1));
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class DbArcIdTest method testEquals.
@Test
public void testEquals() {
DbArcId id1 = new DbArcId(new ObjectId("x", "k", "v"), new DbRelationship("r1"));
assertTrue(id1.equals(id1));
DbArcId id1_eq = new DbArcId(new ObjectId("x", "k", "v"), new DbRelationship("r1"));
assertTrue(id1.equals(id1_eq));
assertTrue(id1_eq.equals(id1));
DbArcId id2 = new DbArcId(new ObjectId("x", "k", "v"), new DbRelationship("r2"));
assertFalse(id1.equals(id2));
DbArcId id3 = new DbArcId(new ObjectId("y", "k", "v"), new DbRelationship("r1"));
assertFalse(id1.equals(id3));
assertFalse(id1.equals(new Object()));
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class RelationshipQueryTest method testSerializability.
@Test
public void testSerializability() throws Exception {
ObjectId oid = new ObjectId("test", "a", "b");
RelationshipQuery query = new RelationshipQuery(oid, "relX");
RelationshipQuery q1 = (RelationshipQuery) Util.cloneViaSerialization(query);
assertNotNull(q1);
assertEquals(oid, q1.getObjectId());
assertEquals("relX", q1.getRelationshipName());
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class SelectQueryMetadataCacheKeyTest method cacheKeyWithPersistentObject.
/**
* Persistent objects should be converted to their ObjectIds.
*/
@Test
public void cacheKeyWithPersistentObject() {
Persistent persistent1 = mock(Persistent.class);
ObjectId objectId1 = mock(ObjectId.class);
when(objectId1.toString()).thenReturn("objId1");
when(persistent1.getObjectId()).thenReturn(objectId1);
Persistent persistent2 = mock(Persistent.class);
ObjectId objectId2 = mock(ObjectId.class);
when(objectId2.toString()).thenReturn("objId2");
when(persistent2.getObjectId()).thenReturn(objectId2);
ExpressionFactory.greaterOrEqualExp("testPath", persistent1).traverse(newHandler());
String s1 = cacheKey.toString();
ExpressionFactory.greaterOrEqualExp("testPath", persistent1).traverse(newHandler());
String s2 = cacheKey.toString();
ExpressionFactory.greaterOrEqualExp("testPath", persistent2).traverse(newHandler());
String s3 = cacheKey.toString();
assertTrue(s1.contains("objId1"));
assertTrue(s3.contains("objId2"));
assertEquals(s1, s2);
assertNotEquals(s2, s3);
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class LifecycleCallbackEventHandlerTest method testDefaultListeners.
@Test
public void testDefaultListeners() {
LifecycleCallbackEventHandler map = new LifecycleCallbackEventHandler(new EntityResolver());
L1 l1 = new L1();
map.addDefaultListener(l1, "callback");
C1 c1 = new C1();
c1.setObjectId(new ObjectId("bogus"));
assertEquals(0, l1.entities.size());
map.performCallbacks(c1);
assertEquals(1, l1.entities.size());
assertTrue(l1.entities.contains(c1));
}
Aggregations