1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.tests.api.request.listening;
14 import java.util.Collection;
15 import java.util.concurrent.atomic.AtomicInteger;
17 import org.junit.Assert;
18 import org.junit.Test;
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.Session;
22 import org.simantics.db.WriteGraph;
23 import org.simantics.db.common.procedure.adapter.ListenerAdapter;
24 import org.simantics.db.common.request.UniqueRead;
25 import org.simantics.db.common.request.WriteRequest;
26 import org.simantics.db.exception.DatabaseException;
27 import org.simantics.db.testing.annotation.Fails;
28 import org.simantics.db.testing.base.ExistingDatabaseTest;
31 public class ObjectsListeningTest extends ExistingDatabaseTest {
35 AtomicInteger executions = new AtomicInteger(0);
38 public void testDisposedListener() throws Exception {
40 final Session session = getSession();
42 session.syncRequest(new WriteRequest() {
45 public void perform(WriteGraph graph) throws DatabaseException {
46 subject = graph.newResource();
47 subrelation = graph.newResource();
48 graph.claim(subrelation, L0.SubrelationOf, L0.HasProperty);
49 graph.claim(subrelation, L0.SubrelationOf, null, L0.List_Next);
54 session.syncRequest(new UniqueRead<Collection<Resource>>() {
57 public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
58 return graph.getObjects(subject, L0.List_Next);
61 }, new ListenerAdapter<Collection<Resource>>() {
64 public void execute(Collection<Resource> result) {
65 executions.incrementAndGet();
70 session.syncRequest(new WriteRequest() {
73 public void perform(WriteGraph graph) throws DatabaseException {
74 graph.claim(subject, subrelation, graph.newResource());
79 Assert.assertEquals(2, executions.get());