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.client;
14 import java.io.IOException;
16 import org.junit.Test;
17 import org.simantics.db.Session;
18 import org.simantics.db.event.SessionEvent;
19 import org.simantics.db.event.SessionListener;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.service.LifecycleSupport;
22 import org.simantics.db.testing.base.ExistingDatabaseTest;
23 import org.simantics.db.testing.common.Tests;
24 import org.simantics.db.testing.impl.Configuration;
26 import fi.vtt.simantics.procore.SessionManagerSource;
28 public class ConnectionTest2 extends ExistingDatabaseTest {
29 // private static final String USERNAME = Configuration.get().username;
30 // private static final String PASSWORD = Configuration.get().password;
31 private static final int RECONNECT_COUNT = Configuration.get().connectionReconnectCount;
33 private int sessionOpened = 0;
34 private int sessionClosed = 0;
35 private synchronized void incOpened() {
38 private synchronized void incClosed() {
42 public void test2() throws DatabaseException {
43 SessionListener sl = new SessionListener() {
45 public void sessionClosed(SessionEvent e) {
46 if (null != e.getCause())
47 fail("Session closed with exception: " + e.getCause().getMessage());
53 public void sessionOpened(SessionEvent e) {
54 if (null != e.getCause())
55 fail("Session opened with exception: " + e.getCause().getMessage());
61 public void sessionException(SessionEvent e) {
62 if (null == e.getCause())
63 fail("Session threw null exception");
65 fail("Session threw exception: " + e.getCause().getMessage());
69 SessionManagerSource.getSessionManager().addSessionListener(sl);
70 for (int i=0; i<RECONNECT_COUNT; ++i) {
73 assertTrue("Open/Closed count mismatch!", sessionOpened == sessionClosed);
74 } catch (IOException e) {
75 throw new DatabaseException("Test failed.", e);
77 // Not totally correct because we do this even if add failed, but...
79 SessionManagerSource.getSessionManager().removeSessionListener(sl);
80 } catch (IOException e1) {
81 throw new DatabaseException("Test failed.", e1);
86 void connectionTest() throws DatabaseException {
88 Session session = Tests.getTestHandler().getSession();
89 LifecycleSupport ls = session.getService(LifecycleSupport.class);
91 // } catch (ClassNotFoundException e) {
92 // throw new DatabaseException("Test failed.", e);