]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/client/CleanShutdownTest2.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / client / CleanShutdownTest2.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.client;
13
14 import java.util.Collection;
15
16 import org.junit.Test;
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.WriteGraph;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.db.testing.annotation.Fails;
22 import org.simantics.db.testing.common.TestBase;
23 import org.simantics.db.testing.common.Tests;
24 import org.simantics.db.testing.common.WriteQuery;
25 import org.simantics.layer0.Layer0;
26 /**
27  * Tests if session can be closed after core crash.
28  * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
29  *
30  */
31 public class CleanShutdownTest2 extends TestBase {
32         private boolean completed = false;
33     @Test
34     @Fails
35         public void testShutdown() throws Exception {
36                 completed = false;
37                 Thread t = new Thread() {
38                         @Override
39                         public void run() {
40                                 try {
41                                         Tests.getTestHandler().getSession().syncRequest(new WriteQuery(CleanShutdownTest2.this) {
42                                                 @Override
43                                                 public void run(WriteGraph g) throws DatabaseException {
44                                                     Layer0 b = Layer0.getInstance(g);
45                                                         Resource instance = g.newResource();
46                                                         g.claim(g.getRootLibrary(), b.ConsistsOf, instance);
47                                                         g.claim(instance, b.InstanceOf, null, b.Type);
48                                                         g.claimLiteral(instance, b.HasName, "Name");
49                                                 }
50                                         });
51                                 } catch (DatabaseException e1) {
52                                         e1.printStackTrace();
53                                 }
54
55                                 try {
56                                     Tests.getTestHandler().getSession().syncRequest(new TestReadRequest() {
57                                                 @Override
58                                                 public void run(ReadGraph g) throws DatabaseException {
59                                                     Layer0 b = Layer0.getInstance(g);
60                                                         Collection<Resource> resources = g.getObjects(g.getRootLibrary(), b.ConsistsOf);
61                                                         // kill the core in the middle of a read transaction
62                                                         Tests.killCore();
63                                                         for (Resource r : resources) {
64                                                                 g.getRelatedValue(r, b.HasName);
65                                                         }
66                                                 }
67                                         });
68                                 } catch (Exception e) {
69                                         // this is the correct behavior for this test
70                                 }
71                                 try {
72                     Tests.closeSession(Tests.getTestHandler().getSession());
73                 } catch (DatabaseException e) {
74                     e.printStackTrace();
75                 }
76                                 completed = true;
77                         }
78                 };
79                 t.start();
80
81                 for (int i = 0; i < 30; i++) {
82                         try {
83                                 Thread.sleep(1000);
84                         } catch (InterruptedException e) {
85
86                         }
87                         if (completed)
88                                 break;
89                 }
90                 if (!completed)
91                         throw new Exception("Core did not shutdown in 30 seconds");
92         }
93
94 }