summaryrefslogtreecommitdiff
path: root/java/test
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2003-09-16 01:41:46 +0000
committerBernard Normier <bernard@zeroc.com>2003-09-16 01:41:46 +0000
commit83cb29a8de333646c9b3e7ac6909accce72e6b5f (patch)
treecc1037886e0d1770d9c1ad412d79c81a5a1d21ad /java/test
parentflex fixes (diff)
downloadice-83cb29a8de333646c9b3e7ac6909accce72e6b5f.tar.bz2
ice-83cb29a8de333646c9b3e7ac6909accce72e6b5f.tar.xz
ice-83cb29a8de333646c9b3e7ac6909accce72e6b5f.zip
Added Freeze Connection and Transaction
Diffstat (limited to 'java/test')
-rw-r--r--java/test/Freeze/complex/Client.java26
-rw-r--r--java/test/Freeze/dbmap/Client.java114
2 files changed, 103 insertions, 37 deletions
diff --git a/java/test/Freeze/complex/Client.java b/java/test/Freeze/complex/Client.java
index 7e1dd4a308e..a70cb1ea492 100644
--- a/java/test/Freeze/complex/Client.java
+++ b/java/test/Freeze/complex/Client.java
@@ -31,7 +31,7 @@ public class Client
validate(String dbName)
throws DBException
{
- Complex.ComplexDict m = new Complex.ComplexDict(_communicator, _envName, dbName, true);
+ Complex.ComplexDict m = new Complex.ComplexDict(_connection, dbName, true);
try
{
@@ -82,7 +82,7 @@ public class Client
"10+(10+(20+(8*(2*(3*2+4+5+6)))))"
};
- Complex.ComplexDict m = new Complex.ComplexDict(_communicator, _envName, dbName, true);
+ Complex.ComplexDict m = new Complex.ComplexDict(_connection, dbName, true);
try
{
@@ -139,15 +139,22 @@ public class Client
return validate(dbName);
}
usage(progName);
-
+
return 0;
}
+
+ private void
+ close()
+ {
+ _connection.close();
+ }
+
private
Client(Ice.Communicator communicator, String envName)
{
_communicator = communicator;
- _envName = envName;
+ _connection = Freeze.Util.createConnection(communicator, envName);
}
@@ -200,7 +207,14 @@ public class Client
communicator = Ice.Util.initialize(holder);
args = holder.value;
Client client = new Client(communicator, envName);
- status = client.run(args, "test");
+ try
+ {
+ status = client.run(args, "test");
+ }
+ finally
+ {
+ client.close();
+ }
}
catch(Exception ex)
{
@@ -226,6 +240,6 @@ public class Client
}
private Ice.Communicator _communicator;
- private String _envName;
+ private Freeze.Connection _connection;
}
diff --git a/java/test/Freeze/dbmap/Client.java b/java/test/Freeze/dbmap/Client.java
index 80857a8ceb9..84b3b2f8a63 100644
--- a/java/test/Freeze/dbmap/Client.java
+++ b/java/test/Freeze/dbmap/Client.java
@@ -20,7 +20,7 @@ public class Client
{
public void
run()
- {
+ {
try
{
for(int i = 0; i < 10; ++i)
@@ -64,13 +64,20 @@ public class Client
ex.printStackTrace();
System.err.println(ex);
}
+ finally
+ {
+ ((Freeze.Map) _map).close();
+ _connection.close();
+ }
}
- ReadThread(java.util.Map m)
+ ReadThread(Ice.Communicator communicator, String envName, String dbName)
{
- _map = m;
+ _connection = Freeze.Util.createConnection(communicator, envName);
+ _map = new ByteIntMap(_connection, dbName, true);
}
+ private Freeze.Connection _connection;
private java.util.Map _map;
}
@@ -100,6 +107,7 @@ public class Client
e.setValue(new Integer(v));
p.remove();
}
+
break;
}
catch(DBDeadlockException ex)
@@ -117,7 +125,7 @@ public class Client
}
}
}
- populateDB(_map);
+ populateDB(_connection, _map);
}
}
catch(Exception ex)
@@ -125,13 +133,20 @@ public class Client
ex.printStackTrace();
System.err.println(ex);
}
+ finally
+ {
+ ((Freeze.Map)_map).close();
+ _connection.close();
+ }
}
- WriteThread(java.util.Map m)
+ WriteThread(Ice.Communicator communicator, String envName, String dbName)
{
- _map = m;
+ _connection = Freeze.Util.createConnection(communicator, envName);
+ _map = new ByteIntMap(_connection, dbName, true);
}
+ private Freeze.Connection _connection;
private java.util.Map _map;
}
@@ -148,23 +163,54 @@ public class Client
}
private static void
- populateDB(java.util.Map m)
+ populateDB(Freeze.Connection connection, java.util.Map m)
throws DBException
{
- for(int j = 0; j < alphabet.length(); ++j)
+ int length = alphabet.length();
+
+ for(;;)
{
- m.put(new Byte((byte)alphabet.charAt(j)), new Integer(j));
+
+ try
+ {
+ Transaction tx = connection.beginTransaction();
+ for(int j = 0; j < length; ++j)
+ {
+ m.put(new Byte((byte)alphabet.charAt(j)), new Integer(j));
+ }
+ tx.commit();
+ break; // for(;;)
+ }
+ catch(Freeze.DBDeadlockException dx)
+ {
+ length = length / 2;
+ // System.err.print("t");
+ //
+ // Try again
+ //
+ }
+ finally
+ {
+ if(connection.currentTransaction() != null)
+ {
+ connection.currentTransaction().rollback();
+ }
+ }
}
}
private static int
- run(String[] args, java.util.Map m)
+ run(String[] args, Ice.Communicator communicator, String envName, String dbName)
throws DBException
{
+ Freeze.Connection connection = Freeze.Util.createConnection(communicator, envName);
+
+ java.util.Map m = new ByteIntMap(connection, dbName, true);
+
//
// Populate the database with the alphabet.
//
- populateDB(m);
+ populateDB(connection, m);
int j;
@@ -208,7 +254,7 @@ public class Client
//
// Re-populate.
//
- populateDB(m);
+ populateDB(connection, m);
{
System.out.print(" testing keySet... ");
@@ -274,8 +320,11 @@ public class Client
test(m.get(new Byte((byte)'n')) != null);
test(m.get(new Byte((byte)'z')) != null);
+ ((Freeze.Map) m).closeAllIterators();
+
java.util.Set entrySet = m.entrySet();
java.util.Iterator p = entrySet.iterator();
+
while(p.hasNext())
{
java.util.Map.Entry e = (java.util.Map.Entry)p.next();
@@ -284,26 +333,28 @@ public class Client
if(v == (byte)'b' || v == (byte)'n' || v == (byte)'z')
{
p.remove();
- try
- {
- p.remove();
- }
- catch(IllegalStateException ex)
- {
- // Expected.
- }
+ try
+ {
+ p.remove();
+ }
+ catch(IllegalStateException ex)
+ {
+ // Expected.
+ }
}
}
+ ((Freeze.Map) m).closeAllIterators();
test(m.size() == 23);
test(m.get(new Byte((byte)'b')) == null);
test(m.get(new Byte((byte)'n')) == null);
test(m.get(new Byte((byte)'z')) == null);
+ System.out.print(" repopulate... ");
//
// Re-populate.
//
- populateDB(m);
+ populateDB(connection, m);
test(m.size() == 26);
@@ -318,6 +369,7 @@ public class Client
p.remove();
}
}
+ ((Freeze.Map) m).closeAllIterators();
test(m.size() == 23);
test(m.get(new Byte((byte)'a')) == null);
@@ -333,7 +385,7 @@ public class Client
//
// Re-populate.
//
- populateDB(m);
+ populateDB(connection, m);
java.util.Set entrySet = m.entrySet();
java.util.Iterator p = entrySet.iterator();
@@ -346,7 +398,7 @@ public class Client
e.setValue(new Integer(v + 100));
}
}
-
+ ((Freeze.Map) m).closeAllIterators();
test(m.size() == 26);
test(m.get(new Byte((byte)'b')) != null);
test(m.get(new Byte((byte)'n')) != null);
@@ -366,16 +418,17 @@ public class Client
test(e.getValue().equals(new Integer(v - (byte)'a')));
}
}
-
System.out.println("ok");
}
+ ((Freeze.Map) m).closeAllIterators();
+
{
System.out.print(" testing concurrent access... ");
System.out.flush();
m.clear();
- populateDB(m);
+ populateDB(connection, m);
java.util.List l = new java.util.ArrayList();
@@ -385,8 +438,8 @@ public class Client
//
for(int i = 0; i < 5; ++i)
{
- l.add(new ReadThread(m));
- l.add(new WriteThread(m));
+ l.add(new ReadThread(communicator, envName, dbName));
+ l.add(new WriteThread(communicator, envName, dbName));
}
//
@@ -421,6 +474,7 @@ public class Client
System.out.println("ok");
}
+ connection.close();
return 0;
}
@@ -445,10 +499,8 @@ public class Client
envName += "db";
}
- ByteIntMap binary = new ByteIntMap(communicator, envName, "binary", true);
- System.out.println("testing encoding...");
- status = run(args, binary);
- binary.close();
+ System.out.println("testing encoding...");
+ status = run(args, communicator, envName, "binary");
}
catch(DBException ex)
{