]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/clusterControl/CreateAndCollectBigClusterInUpdateTest.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / support / clusterControl / CreateAndCollectBigClusterInUpdateTest.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.support.clusterControl;
13
14 import java.util.Arrays;
15
16 import org.junit.Test;
17 import org.simantics.databoard.Bindings;
18 import org.simantics.db.Resource;
19 import org.simantics.db.WriteGraph;
20 import org.simantics.db.common.request.WriteRequest;
21 import org.simantics.db.event.ChangeEvent;
22 import org.simantics.db.event.ChangeListener;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.db.service.ClusterControl;
25 import org.simantics.db.service.GraphChangeListenerSupport;
26 import org.simantics.db.testing.cases.FreshDatabaseTest;
27
28 public class CreateAndCollectBigClusterInUpdateTest extends FreshDatabaseTest {
29
30         Resource resource1;
31         Resource resource2;
32         Resource resource3;
33         
34         @Test
35     public void test() throws Exception{
36
37         GraphChangeListenerSupport changeListenerSupport = getSession().getService(GraphChangeListenerSupport.class);
38         changeListenerSupport.addMetadataListener( new ChangeListener() {
39                         
40                         @Override
41                         public void graphChanged(ChangeEvent e) throws DatabaseException {
42
43                                 // Collect
44                         ClusterControl cc = e.getGraph().getService(ClusterControl.class);
45                         cc.collectClusters(Integer.MAX_VALUE);
46
47                         Arrays.equals(testArray(10), (byte[])e.getGraph().getValue(resource1, Bindings.BYTE_ARRAY));
48                         Arrays.equals(testArray(100000), (byte[])e.getGraph().getValue(resource2, Bindings.BYTE_ARRAY));
49                         Arrays.equals(testArray(10), (byte[])e.getGraph().getValue(resource3, Bindings.BYTE_ARRAY));
50                                 
51                         }
52                         
53                 } );
54
55         
56         getSession().sync(new WriteRequest() {
57
58                         @Override
59                         public void perform(WriteGraph g) throws DatabaseException {
60                                 
61                 g.flushCluster();
62
63                 for(int i=0;i<1000;i++) g.newResource();
64                 resource1 = g.newResource();
65                 g.claimValue(resource1, testArray(10), Bindings.BYTE_ARRAY);
66                 
67                 for(int i=0;i<1000;i++) g.newResource();
68                 resource2 = g.newResource();
69                 g.claimValue(resource2, testArray(100000), Bindings.BYTE_ARRAY);
70                 
71                 for(int i=0;i<1000;i++) g.newResource();
72                 resource3 = g.newResource();
73                 g.claimValue(resource3, testArray(10), Bindings.BYTE_ARRAY);
74                                 
75                         }
76                 
77         });
78
79     }
80         
81         byte[] testArray(int size) {
82                 byte[] result = new byte[size];
83                 for(int i=0;i<size;i++) result[i] = (byte)i;
84                 return result;
85         }
86
87 }