Changeset 5251
- Timestamp:
- 2011-12-09 15:11:55 (19 months ago)
- Location:
- trunk/apps/tester/src/main/java/org/lilyproject/tools/tester
- Files:
-
- 2 edited
-
ReadAction.java (modified) (2 diffs)
-
TestFieldType.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/apps/tester/src/main/java/org/lilyproject/tools/tester/ReadAction.java
r5129 r5251 8 8 import javax.naming.OperationNotSupportedException; 9 9 10 import org.apache.commons.lang.ArrayUtils; 10 11 import org.codehaus.jackson.JsonNode; 11 12 import org.lilyproject.repository.api.*; … … 68 69 ValueType valueType = fieldType.getValueType(); 69 70 if (valueType.getDeepestValueType() instanceof BlobValueType) { 70 if (valueType.isMultiValue()) { 71 List<Object> multivalues = (List<Object>)(entry.getValue()); 72 int multivalueIndex = randomIndex(multivalues.size()); 73 if (valueType.isHierarchical()) { 74 Object[] hierarchyValues = ((HierarchyPath)(multivalues.get(multivalueIndex))).getElements(); 75 int hierarchyIndex = randomIndex(hierarchyValues.length); 76 Blob blob = (Blob)hierarchyValues[hierarchyIndex]; 77 InputStream inputStream = testActionContext.repository.getInputStream(readRecord, fieldName, multivalueIndex, hierarchyIndex); 78 readBlobBytes(blob, inputStream); 79 } else { 80 Blob blob = (Blob)(multivalues.get(multivalueIndex)); 81 InputStream inputStream = testActionContext.repository.getInputStream(readRecord.getId(), readRecord.getVersion(), fieldName, multivalueIndex, null); 82 readBlobBytes(blob, inputStream); 83 } 84 } else if (valueType.isHierarchical()) { 85 Object[] hierarchyValues = ((HierarchyPath)(entry.getValue())).getElements(); 86 int hierarchyIndex = randomIndex(hierarchyValues.length); 87 Blob blob = (Blob)hierarchyValues[hierarchyIndex]; 88 BlobAccess blobAccess = testActionContext.repository.getBlob(readRecord.getId(), readRecord.getVersion(), fieldName, null, hierarchyIndex); 89 InputStream inputStream = blobAccess.getInputStream(); 90 readBlobBytes(blob, inputStream); 91 } else { 92 Set<Object> values = valueType.getValues(entry.getValue()); 93 Blob blob = (Blob)values.toArray()[0]; 94 InputStream inputStream = testActionContext.repository.getInputStream(readRecord, fieldName); 95 readBlobBytes(blob, inputStream); 96 } 71 readBlobs(readRecord, fieldName, entry.getValue(), valueType); 97 72 } 98 99 73 } 100 74 } 101 75 76 private void readBlobs(Record readRecord, QName fieldName, Object value, ValueType valueType, int... indexes) 77 throws RepositoryException, InterruptedException, IOException { 78 if (valueType.getBaseName().equals("LIST")) { 79 List<Object> multivalues = (List<Object>) (value); 80 int multivalueIndex = randomIndex(multivalues.size()); 81 Object subValue = (multivalues.get(multivalueIndex)); 82 indexes = ArrayUtils.add(indexes, multivalueIndex); 83 readBlobs(readRecord, fieldName, subValue, valueType.getNestedValueType(), indexes); 84 } else if (valueType.getBaseName().equals("PATH")) { 85 Object[] hierarchyValues = ((HierarchyPath) (value)).getElements(); 86 int hierarchyIndex = randomIndex(hierarchyValues.length); 87 Object subValue = hierarchyValues[hierarchyIndex]; 88 indexes = ArrayUtils.add(indexes, hierarchyIndex); 89 readBlobs(readRecord, fieldName, subValue, valueType.getNestedValueType(), indexes); 90 } else { 91 Blob blob = (Blob) value; 92 InputStream inputStream = testActionContext.repository.getInputStream(readRecord, fieldName, indexes); 93 readBlobBytes(blob, inputStream); 94 } 95 } 96 102 97 private int randomIndex(int arrayLength) { 103 98 return (int)(Math.random() * arrayLength); -
trunk/apps/tester/src/main/java/org/lilyproject/tools/tester/TestFieldType.java
r5239 r5251 270 270 } else { 271 271 Object value = record.getField(fieldType.getName()); 272 return update MultiValue(testAction, value);273 } 274 } 275 276 private ActionResult update MultiValue(TestAction testAction, Object value) {277 if ( fieldType.getValueType().isMultiValue()) {278 List<Object> values = (List<Object>) value;272 return updateLinkValue(testAction, value, fieldType.getValueType()); 273 } 274 } 275 276 private ActionResult updateLinkValue(TestAction testAction, Object value, ValueType valueType) { 277 if (valueType.getBaseName().equals("LIST")) { 278 List<Object> values = (List<Object>) value; 279 279 int index = (int) (Math.random() * values.size()); 280 ActionResult result = update Hierarchical(testAction, values.get(index));280 ActionResult result = updateLinkValue(testAction, values.get(index), valueType.getNestedValueType()); 281 281 if (result.success && result.object != null) { 282 282 values.add(index, result.object); 283 283 return new ActionResult(true, values, result.duration); 284 284 } 285 return updateHierarchical(testAction, values.get(index)); 286 } else { 287 return updateHierarchical(testAction, value); 288 } 289 } 290 291 private ActionResult updateHierarchical(TestAction testAction, Object value) { 292 if (fieldType.getValueType().isHierarchical()) { 293 HierarchyPath path = (HierarchyPath)value; 285 return result; 286 } else if (valueType.getBaseName().equals("PATH")) { 287 HierarchyPath path = (HierarchyPath) value; 294 288 Object[] values = path.getElements(); 295 289 int index = (int) (Math.random() * values.length); 296 290 // LinkedRecordTypeName should only be given in case of link fields 297 ActionResult result = updateLink (testAction, (Link)values[index]);291 ActionResult result = updateLinkValue(testAction, values[index], valueType.getNestedValueType()); 298 292 if (result.success && result.object != null) { 299 293 values[index] = result.object; … … 302 296 return result; 303 297 } else { 304 return updateLink(testAction, (Link) value);298 return updateLink(testAction, (Link) value); 305 299 } 306 300 }
Note: See TracChangeset
for help on using the changeset viewer.