18 package testsuite.clusterj;
20 import java.util.ArrayList;
21 import java.util.List;
23 import testsuite.clusterj.model.BinaryPK;
27 protected int NUMBER_OF_INSTANCES = 15;
28 protected List<BinaryPK> instances =
new ArrayList<BinaryPK>();
32 createSessionFactory();
39 }
catch (Throwable t) {
63 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
64 byte[] key = getStoragePK(
i);
66 verifyResult(
"find ", result,
i,
false);
74 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
77 instance.setName(getValue(NUMBER_OF_INSTANCES -
i));
79 verifyStorage(
"update ", instance,
i,
true);
83 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
85 byte[] key = getStoragePK(
i);
87 verifyResult(
"update verify", instance,
i,
true);
94 protected void delete() {
96 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
103 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
105 byte[] key = getStoragePK(
i);
107 errorIfNotEqual(
"Failed to delete instance: " +
i, null, instance);
116 for (
int i = 0;
i < NUMBER_OF_INSTANCES; ++
i) {
118 if (
getDebug()) System.out.println(toString(instance));
119 instances.add(instance);
129 instance.setId(getStoragePK(index));
130 instance.setNumber(index);
131 instance.setName(getValue(index));
137 result.append(
"BinaryPK[");
138 result.append(toString(instance.getId()));
139 result.append(
"]: ");
140 result.append(instance.getNumber());
141 result.append(
", \"");
142 result.append(instance.getName());
143 result.append(
"\".");
144 return result.toString();
147 protected byte[] getStoragePK(
int index) {
148 return new byte[] {0, (byte)(index/256), (byte)(index%256)};
151 protected byte[] getResultPK(
int index) {
152 byte[] result =
new byte[255];
153 result[1] = (byte)(index/256);
154 result[2] = (byte)(index%256);
158 protected String getValue(
int index) {
159 return "Value " +
index;
162 protected void verifyStorage(
String where, BinaryPK instance,
int index,
boolean updated) {
163 errorIfNotEqual(where +
"id failed", toString(getStoragePK(index)), toString(instance.getId()));
164 errorIfNotEqual(where +
"number failed", index, instance.getNumber());
166 errorIfNotEqual(where +
"Value failed", getValue(NUMBER_OF_INSTANCES - index), instance.getName());
168 errorIfNotEqual(where +
"Value failed", getValue(index), instance.getName());
173 protected void verifyResult(
String where, BinaryPK instance,
int index,
boolean updated) {
174 errorIfNotEqual(where +
"id failed", toString(getResultPK(index)), toString(instance.getId()));
175 errorIfNotEqual(
"number failed", index, instance.getNumber());
177 errorIfNotEqual(where +
"Value failed", getValue(NUMBER_OF_INSTANCES - index), instance.getName());
179 errorIfNotEqual(where +
"Value failed", getValue(index), instance.getName());
184 private String toString(byte[]
id) {
185 StringBuilder builder =
new StringBuilder();
186 for (
int i = 0;
i <
id.length; ++
i) {
187 builder.append(
String.valueOf(
id[
i]));
190 return builder.toString();