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.support.clusterControl;
14 import java.util.Arrays;
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;
28 public class CreateAndCollectBigClusterInUpdateTest extends FreshDatabaseTest {
35 public void test() throws Exception{
37 GraphChangeListenerSupport changeListenerSupport = getSession().getService(GraphChangeListenerSupport.class);
38 changeListenerSupport.addMetadataListener( new ChangeListener() {
41 public void graphChanged(ChangeEvent e) throws DatabaseException {
44 ClusterControl cc = e.getGraph().getService(ClusterControl.class);
45 cc.collectClusters(Integer.MAX_VALUE);
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));
56 getSession().sync(new WriteRequest() {
59 public void perform(WriteGraph g) throws DatabaseException {
63 for(int i=0;i<1000;i++) g.newResource();
64 resource1 = g.newResource();
65 g.claimValue(resource1, testArray(10), Bindings.BYTE_ARRAY);
67 for(int i=0;i<1000;i++) g.newResource();
68 resource2 = g.newResource();
69 g.claimValue(resource2, testArray(100000), Bindings.BYTE_ARRAY);
71 for(int i=0;i<1000;i++) g.newResource();
72 resource3 = g.newResource();
73 g.claimValue(resource3, testArray(10), Bindings.BYTE_ARRAY);
81 byte[] testArray(int size) {
82 byte[] result = new byte[size];
83 for(int i=0;i<size;i++) result[i] = (byte)i;