001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
004: //
005: // All Rights Reserved
006: //
007: // This program is free software; you can redistribute it and/or modify
008: // it under the terms of the GNU General Public License and GNU Library
009: // General Public License as published by the Free Software Foundation;
010: // either version 2, or (at your option) any later version.
011: //
012: // This program is distributed in the hope that it will be useful,
013: // but WITHOUT ANY WARRANTY; without even the implied warranty of
014: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: // GNU General Public License and GNU Library General Public License
016: // for more details.
017: //
018: // You should have received a copy of the GNU General Public License
019: // and GNU Library General Public License along with this program; if
020: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
021: // MA 02139, USA.
022: //
023: ///////////////////////////////////////////////////////////////////////////////
024: package org.myoodb.regression;
025:
026: import org.myoodb.objects.*;
027:
028: public class Client {
029: public static int PORT = 54321;
030: public static String USERNAME = "admin";
031: public static String PASSWORD = "admin";
032:
033: public static void main(String args[]) throws Exception {
034: final org.myoodb.MyOodbDatabase db = org.myoodb.MyOodbDatabase
035: .open("tcp://localhost:" + PORT, USERNAME, PASSWORD);
036: final Count count;
037:
038: boolean first = false;
039: org.myoodb.collectable.LinkedList list = (org.myoodb.collectable.LinkedList) db
040: .getRoot("Regressions");
041: if (list == null) {
042: list = (org.myoodb.collectable.LinkedList) db.createRoot(
043: "Regressions",
044: "org.myoodb.collectable.LinkedListDbImpl");
045: //list = (org.myoodb.collectable.LinkedList) db.createRoot("Regressions", org.myoodb.collectable.LinkedListDbImpl.class);
046:
047: count = (Count) db
048: .createObject("org.myoodb.objects.CountDbImpl");
049: //count = (Count) db.createObject(CountDbImpl.class);
050:
051: list.add(count);
052: first = true;
053: } else {
054: System.out.println("Regressions: " + list);
055: count = (Count) list.getFirst();
056: }
057:
058: Thread.sleep(2500);
059:
060: Runnable explicitWrites = new Runnable() {
061: public void run() {
062: try {
063: Count copy = (Count) count.getSelf();
064:
065: for (int i = 0; i < 1000; i++) {
066: for (int j = 0; j < 100000; j++) {
067: org.myoodb.MyOodbTransaction tx = db
068: .createTransaction();
069: tx.begin();
070: copy.setCount(copy.getCount() + 1);
071: tx.begin();
072: copy.setCount(copy.getCount() + 1);
073: tx.begin();
074: copy.setCount(copy.getCount() + 1);
075: tx.begin();
076: copy.setCount(copy.getCount() + 1);
077: tx.begin();
078: copy.setCount(copy.getCount() + 1);
079:
080: while (tx.getTransactions().size() != 0) {
081: if ((i % 10) == 0) {
082: tx.rollback();
083: } else {
084: tx.commit();
085: }
086: }
087: }
088: }
089: } catch (Exception e) {
090: e.printStackTrace();
091: }
092: }
093: };
094:
095: if (first == true) {
096: Thread thread = new Thread(explicitWrites);
097: thread.setDaemon(true);
098: thread.start();
099: }
100:
101: Runnable mightyWrites = new Runnable() {
102: public void run() {
103: try {
104: Count copy = (Count) count.getSelf();
105: ((org.myoodb.MyOodbProxy) copy)
106: .setWriteMode(org.myoodb.MyOodbAccess.MIGHTY_WRITE);
107:
108: for (int i = 0; i < 100000; i++) {
109: copy.setCount(copy.getCount() + 1);
110: System.out.print("," + copy.getCount());
111: System.out.flush();
112: }
113: } catch (Exception e) {
114: e.printStackTrace();
115: }
116: }
117: };
118:
119: /*
120: for (int i = 0; i < 5; i++)
121: {
122: Thread thread = new Thread(mightyWrites);
123: thread.setDaemon(true);
124: thread.start();
125: }
126: */
127:
128: while (true) {
129: System.out.print(".");
130: System.out.flush();
131: Thread.sleep(1000);
132: }
133: }
134: }
|