18 package testsuite.clusterj;
20 import java.util.ArrayList;
21 import java.util.List;
23 import testsuite.clusterj.model.BinaryPK;
24 import testsuite.clusterj.model.DynamicPK;
28 protected int NUMBER_OF_INSTANCES = 15;
29 protected List<DynamicPK> instances =
new ArrayList<DynamicPK>();
33 createSessionFactory();
39 run(DynamicBinaryPK.class);
40 run(DynamicVarbinaryPK.class);
41 run(DynamicLongvarbinaryPK.class);
45 public void run(Class<? extends DynamicPK> cls) {
54 public static class DynamicBinaryPK
extends DynamicPK {
61 public static class DynamicVarbinaryPK
extends DynamicPK {
68 public static class DynamicLongvarbinaryPK
extends DynamicPK {
71 return "longvarbinarypk";
75 protected void deleteAll(Class<? extends DynamicPK> cls) {
80 }
catch (Throwable t) {
93 protected void find(Class<? extends DynamicPK> cls) {
94 String where =
"find " + cls.getName();
95 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
96 byte[] key = getPK(
i);
98 verify(where, result,
i,
false);
104 protected void update(Class<? extends DynamicPK> cls) {
106 String where =
"update before " + cls.getName();
107 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
110 instance.setName(getValue(NUMBER_OF_INSTANCES -
i));
112 verify(where, instance,
i,
true);
116 where =
"update after " + cls.getName();
117 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
119 byte[] key = getPK(
i);
121 verify(where, instance,
i,
true);
128 protected void delete(Class<? extends DynamicPK> cls) {
130 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
137 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
139 byte[] key = getPK(
i);
141 errorIfNotEqual(
"Failed to delete instance: " +
i, null, instance);
151 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
153 if (
getDebug()) System.out.println(toString(instance));
154 instances.add(instance);
164 instance.setId(getPK(index));
165 instance.setNumber(index);
166 instance.setName(getValue(index));
173 result.append(toString(instance.getId()));
174 result.append(
"]: ");
175 result.append(instance.getNumber());
176 result.append(
", \"");
177 result.append(instance.getName());
178 result.append(
"\".");
179 return result.toString();
182 protected byte[] getPK(
int index) {
183 byte[] result =
new byte[255];
184 result[1] = (byte)(index/256);
185 result[2] = (byte)(index%256);
189 protected String getValue(
int index) {
190 return "Value " +
index;
193 protected void verify(
String where, DynamicPK instance,
int index,
boolean updated) {
194 errorIfNotEqual(where +
"id failed", toString(getPK(index)), toString(instance.getId()));
195 errorIfNotEqual(where +
"number failed", index, instance.getNumber());
197 errorIfNotEqual(where +
" Value failed", getValue(NUMBER_OF_INSTANCES - index), instance.getName());
199 errorIfNotEqual(where +
" Value failed", getValue(index), instance.getName());
204 private String toString(byte[]
id) {
205 StringBuilder builder =
new StringBuilder();
206 for (
int i = 0;
i <
id.length; ++
i) {
207 builder.append(
String.valueOf(
id[
i]));
210 return builder.toString();