]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/api/story/sessionGarbageCollection/CollectDuringWriteAndRead.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / api / story / sessionGarbageCollection / CollectDuringWriteAndRead.java
1 package org.simantics.db.tests.api.story.sessionGarbageCollection;
2
3 import org.simantics.db.Resource;
4 import org.simantics.db.Session;
5 import org.simantics.db.WriteGraph;
6 import org.simantics.db.common.request.WriteResultRequest;
7 import org.simantics.db.exception.DatabaseException;
8 import org.simantics.db.layer0.util.SessionGarbageCollection;
9 import org.simantics.db.testing.annotation.Fails;
10 import org.simantics.db.testing.base.CommandSequenceTest;
11 import org.simantics.db.testing.common.Command;
12 import org.simantics.db.testing.common.CommandSequenceEnvironment;
13 import org.simantics.db.testing.common.CommandSpec;
14 import org.simantics.db.testing.common.Kill;
15 import org.simantics.db.testing.common.Reconnect;
16
17 /**
18  * @author Antti Villberg
19  */
20 @Fails
21 public class CollectDuringWriteAndRead extends CommandSequenceTest {
22
23         private final int SEQUENCE_SIZE = 300;
24         private final int LIST_SIZE = 500;
25
26         private Resource root;
27         private int index;
28
29         public Resource getRoot() {
30                 return root;
31         }
32
33         public int incrementAndGetIndex() {
34                 return index++;
35         }
36
37         public int getListSize() {
38                 return LIST_SIZE;
39         }
40
41         @Override
42         protected int getSequenceSize() {
43                 return SEQUENCE_SIZE;
44         }
45
46         @Override
47         protected CommandSpec<?>[] getFactories() {
48                 return new CommandSpec[] {
49                                 CommandSpec.make(AddList.class, 1.0),
50                                 CommandSpec.make(RemoveList.class, 1.0),
51                                 CommandSpec.make(AppendList.class, 0.5),
52                                 CommandSpec.make(Read.class, 0.1),
53                                 CommandSpec.make(AddListAndKill.class, 0.02),
54                                 CommandSpec.make(Reconnect.class, 0.02),
55                                 CommandSpec.make(Kill.class, 0.02)
56                 };
57         }
58
59         protected Command[] beforeSequence(CommandSequenceEnvironment environment) throws Exception {
60
61                 return new Command[] {
62
63                                 new Command<CommandSequenceEnvironment>() {
64
65                                         @Override
66                                         public void run(CommandSequenceEnvironment environment) throws Exception {
67
68                                                 Session s = getSession();
69                                                 root = s.syncRequest(new WriteResultRequest<Resource>() {
70
71                                                         @Override
72                                                         public Resource perform(WriteGraph graph) throws DatabaseException {
73                                                                 return graph.newResource();
74                                                         }
75
76                                                 });
77                                                 for(int i=0;i<10;i++) new AddList().run(CollectDuringWriteAndRead.this);
78                                                 SessionGarbageCollection.gc(null, s, true, null, 0, 0);
79
80                                         }
81
82                                 }
83
84                 };
85
86
87         }
88
89 }