]> gerrit.simantics Code Review - simantics/platform.git/blob
6811ce5f481ef7f7f6ff424e378375d5107f643a
[simantics/platform.git] /
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.tests.api.request.listening;
13
14 import java.util.Collection;
15 import java.util.concurrent.atomic.AtomicInteger;
16
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;
29
30 @Fails
31 public class ObjectsListeningTest extends ExistingDatabaseTest {
32
33         Resource subject;
34         Resource subrelation;
35         AtomicInteger executions = new AtomicInteger(0);
36         
37         @Test
38     public void testDisposedListener() throws Exception {
39                 
40         final Session session = getSession();
41
42         session.syncRequest(new WriteRequest() {
43
44                         @Override
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);
50                         }
51                         
52                 });
53         
54         session.syncRequest(new UniqueRead<Collection<Resource>>() {
55
56                         @Override
57                         public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
58                                 return graph.getObjects(subject, L0.List_Next);
59                         }
60                 
61         }, new ListenerAdapter<Collection<Resource>>() {
62                 
63                 @Override
64                 public void execute(Collection<Resource> result) {
65                         executions.incrementAndGet();
66                 }
67                 
68         });
69         
70         session.syncRequest(new WriteRequest() {
71
72                         @Override
73                         public void perform(WriteGraph graph) throws DatabaseException {
74                                 graph.claim(subject, subrelation, graph.newResource());
75                         }
76                         
77                 });
78
79         Assert.assertEquals(2, executions.get());
80         
81     }
82 }