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.translog;
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 TransLogTester {
33:
34: public static void main(String[] args) throws Exception {
35: int numberOfInstances = 100000;
36: if (args.length > 0) {
37: numberOfInstances = Integer.parseInt(args[0]);
38: }
39:
40: CompassConfiguration conf = new CompassConfiguration();
41: conf
42: .configure("/org/compass/core/load/translog/compass.cfg.xml");
43: File testPropsFile = new File("compass.test.properties");
44: if (testPropsFile.exists()) {
45: Properties testProps = new Properties();
46: testProps.load(new FileInputStream(testPropsFile));
47: conf.getSettings().addSettings(testProps);
48: }
49: conf.addClass(A.class);
50: Compass compass = conf.buildCompass();
51: compass.getSearchEngineIndexManager().deleteIndex();
52: compass.getSearchEngineIndexManager().verifyIndex();
53:
54: CompassSession session = compass.openSession();
55: // session.getSettings().setClassSetting(RuntimeLuceneEnvironment.Transaction.TransLog.TYPE, FSTransLog.class);
56: CompassTransaction tr = session.beginTransaction();
57: for (int i = 0; i < numberOfInstances; i++) {
58: if (i % 1000 == 0) {
59: System.out.println("Indexed [" + i + "] instances");
60: }
61: A a = new A();
62: a.setId(new Long(i));
63: a.setData1("test data 1");
64: a.setData2("test data 2");
65: a.setIndexTime(new Date());
66: session.save(a);
67: }
68: System.out.println("Committing Transaction");
69: tr.commit();
70: session.close();
71: System.out.println("Indexing Complete");
72: }
73: }
|