--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.tests.api.request.listening;
+
+import java.util.Collection;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.procedure.adapter.ListenerAdapter;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.testing.annotation.Fails;
+import org.simantics.db.testing.base.ExistingDatabaseTest;
+
+@Fails
+public class ObjectsListeningTest extends ExistingDatabaseTest {
+
+ Resource subject;
+ Resource subrelation;
+ AtomicInteger executions = new AtomicInteger(0);
+
+ @Test
+ public void testDisposedListener() throws Exception {
+
+ final Session session = getSession();
+
+ session.syncRequest(new WriteRequest() {
+
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ subject = graph.newResource();
+ subrelation = graph.newResource();
+ graph.claim(subrelation, L0.SubrelationOf, L0.HasProperty);
+ graph.claim(subrelation, L0.SubrelationOf, null, L0.List_Next);
+ }
+
+ });
+
+ session.syncRequest(new UniqueRead<Collection<Resource>>() {
+
+ @Override
+ public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
+ return graph.getObjects(subject, L0.List_Next);
+ }
+
+ }, new ListenerAdapter<Collection<Resource>>() {
+
+ @Override
+ public void execute(Collection<Resource> result) {
+ executions.incrementAndGet();
+ }
+
+ });
+
+ session.syncRequest(new WriteRequest() {
+
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ graph.claim(subject, subrelation, graph.newResource());
+ }
+
+ });
+
+ Assert.assertEquals(2, executions.get());
+
+ }
+}