]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/client/ReserveIdsTest2.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / client / ReserveIdsTest2.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
15 import org.junit.Test;
16 import org.simantics.db.WriteGraph;
17 import org.simantics.db.common.request.WriteRequest;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.db.service.DebugSupport;
20 import org.simantics.db.testing.base.TestCommonNoVirtual;
21 import org.simantics.db.testing.common.Client;
22 import org.simantics.db.testing.common.ClientFactory;
23
24 @SuppressWarnings("deprecation") // No replacement given so now way to fix this error.
25 public class ReserveIdsTest2 extends TestCommonNoVirtual {
26
27     private String nextId;
28     
29     @Test
30     public void test() throws DatabaseException {
31 //        ServerAddress serverAddress = getSessionContext().getAddress();
32         String clientId = getRandomString();
33         Client client1 = ClientFactory.create(clientId);
34         try {
35             client1.getSession().syncRequest(new WriteRequest() {
36                 @Override
37                 public void perform(WriteGraph graph) throws DatabaseException {
38                     graph.flushCluster();
39                     graph.newResource();
40                     nextId = graph.getService(DebugSupport.class).query(graph, "print nextId");
41                 }
42             });
43         } finally {
44             client1.close();
45         }
46         Client client2 = ClientFactory.create(clientId);
47         try {
48             client2.getSession().syncRequest(new WriteRequest() {
49                 @Override
50                 public void perform(WriteGraph graph) throws DatabaseException {
51                     String nextId = graph.getService(DebugSupport.class).query(graph, "print nextId");
52                     //assertTrue(nextId.equals(ReserveIdsTest2.this.nextId));
53                     int i1 = Integer.parseInt(nextId.substring(0, nextId.indexOf('#')));
54                     String t = ReserveIdsTest2.this.nextId;
55                     int i2 = Integer.parseInt(t.substring(0, t.indexOf('#')));
56                     assertTrue(i1 == i2+1);
57                 }
58             });
59         } finally {
60             client2.close();
61         }
62     }
63 }