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.thread;
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;
24 * This test ensures that synchronous requests are processed in same thread
27 public class ThreadingTest1 extends ExistingDatabaseTest {
30 public void test() throws Exception {
32 Session session = getSession();
34 QueryControl control = session.getService(QueryControl.class);
35 if(control.getAmountOfQueryThreads() == 1) return;
37 int result = session.syncRequest(new Read<Integer>() {
40 public Integer perform(ReadGraph graph) throws DatabaseException {
42 final int thread = graph.thread();
44 return graph.syncRequest(new Read<Integer>() {
47 public Integer perform(ReadGraph graph) throws DatabaseException {
49 assert(thread == graph.thread());
60 public int hashCode() {
64 }, new ListenerAdapter<Integer>() {
66 public boolean isDisposed() {