01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.core.load.concurrentcommit;
18:
19: import java.io.File;
20: import java.io.FileInputStream;
21: import java.util.Date;
22: import java.util.Properties;
23:
24: import org.compass.core.Compass;
25: import org.compass.core.CompassSession;
26: import org.compass.core.CompassTransaction;
27: import org.compass.core.config.CompassConfiguration;
28:
29: /**
30: * @author kimchy
31: */
32: public class ConcurrentCommitTester {
33:
34: private static final String[] datas = new String[] {
35: "The big brown fox",
36: "The hitchiker guide to the galaxy",
37: "White russian",
38: "The player of Games",
39: "But it's so simple. All I have to do is divine from what I know"
40: + "of you: are you the sort of man who would put the poison into his"
41: + "own goblet or his enemy's? Now, a clever man would put the poison"
42: + "into his own goblet, because he would know that only a great fool"
43: + "would reach for what he was given. I am not a great fool, so I"
44: + "can clearly not choose the wine in front of you. But you must"
45: + "have known I was not a great fool, you would have counted on it,"
46: + "so I can clearly not choose the wine in front of me.",
47: "I am the law, now give me my white russian" };
48:
49: public static void main(String[] args) throws Exception {
50: CompassConfiguration conf = new CompassConfiguration();
51: conf
52: .configure("/org/compass/core/load/concurrentcommit/compass.cfg.xml");
53: File testPropsFile = new File("compass.test.properties");
54: if (testPropsFile.exists()) {
55: Properties testProps = new Properties();
56: testProps.load(new FileInputStream(testPropsFile));
57: conf.getSettings().addSettings(testProps);
58: }
59: conf
60: .addResource("org/compass/core/load/concurrentcommit/A.cpm.xml");
61: Compass compass = conf.buildCompass();
62: compass.getSearchEngineIndexManager().deleteIndex();
63: compass.getSearchEngineIndexManager().createIndex();
64:
65: System.out.println("Starting Test");
66: long time = System.currentTimeMillis();
67: for (long i = 0; i < 200D; i++) {
68: System.out.println("Cycle [" + i + "]");
69: A a = new A();
70: a.id = i;
71: a.value1 = datas[(int) (i % datas.length)];
72: a.value2 = datas[(int) ((i + 1) % datas.length)];
73: a.indexTime = new Date();
74:
75: CompassSession session = compass.openSession();
76: CompassTransaction tr = session.beginTransaction();
77:
78: session.save("a1", a);
79: session.save("a2", a);
80: session.save("a3", a);
81: session.save("a4", a);
82: session.save("a5", a);
83:
84: tr.commit();
85: session.close();
86:
87: if ((i % 10) == 0) {
88: System.out.println("Optimizing [" + i + "]");
89: compass.getSearchEngineOptimizer().optimize();
90: }
91: }
92:
93: System.out.println("Test Finished in ["
94: + (System.currentTimeMillis() - time) + "]");
95:
96: compass.close();
97: }
98: }
|