]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/request/thread/ThreadingTest2.java
Made DB ListenerAdapter abstract to force isDisposed implementation
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / request / thread / ThreadingTest2.java
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.thread;
13
14 import org.junit.Test;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.Session;
17 import org.simantics.db.common.procedure.adapter.ListenerAdapter;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.db.request.Read;
20 import org.simantics.db.service.QueryControl;
21 import org.simantics.db.testing.base.ExistingDatabaseTest;
22
23 /*
24  * This test ensures that synchronous requests are processed in same thread
25  * 
26  */
27 public class ThreadingTest2 extends ExistingDatabaseTest {
28         
29         @Test
30     public void test() throws Exception {
31                 
32                 Session session = getSession();
33                 
34                 QueryControl control = session.getService(QueryControl.class);
35                 if(control.getAmountOfQueryThreads() == 1) return;
36                 
37                 int result = session.syncRequest(new Read<Integer>() {
38
39             @Override
40             public Integer perform(ReadGraph graph) throws DatabaseException {
41                 
42                 final int thread = graph.thread();
43                 
44                 return graph.syncRequest(new Read<Integer>() {
45
46                                         @Override
47                                         public Integer perform(ReadGraph graph) throws DatabaseException {
48                                                 
49                                                 assert(thread == graph.thread());
50                                                 
51                                                 return 1;
52                                                 
53                                         }
54                                         
55                 });
56                 
57             }
58             
59             @Override
60             public int hashCode() {
61                 return 0;
62             }
63                     
64                 }, new ListenerAdapter<Integer>() {
65                         @Override
66                         public boolean isDisposed() {
67                                 return false;
68                         }
69                 });
70                 
71                 assert(result == 1);
72                 
73         }
74
75 }