Changeset 5251


Ignore:
Timestamp:
2011-12-09 15:11:55 (19 months ago)
Author:
evert
Message:

Stop using the deprecated isMultivalue and isHierarchical calls in the Tester tool.

Location:
trunk/apps/tester/src/main/java/org/lilyproject/tools/tester
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/apps/tester/src/main/java/org/lilyproject/tools/tester/ReadAction.java

    r5129 r5251  
    88import javax.naming.OperationNotSupportedException; 
    99 
     10import org.apache.commons.lang.ArrayUtils; 
    1011import org.codehaus.jackson.JsonNode; 
    1112import org.lilyproject.repository.api.*; 
     
    6869            ValueType valueType = fieldType.getValueType(); 
    6970            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); 
    9772            } 
    98              
    9973        } 
    10074    } 
    10175     
     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 
    10297    private int randomIndex(int arrayLength) { 
    10398        return (int)(Math.random() * arrayLength); 
  • trunk/apps/tester/src/main/java/org/lilyproject/tools/tester/TestFieldType.java

    r5239 r5251  
    270270        } else { 
    271271            Object value = record.getField(fieldType.getName()); 
    272             return updateMultiValue(testAction, value); 
    273         } 
    274     } 
    275      
    276     private ActionResult updateMultiValue(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; 
    279279            int index = (int) (Math.random() * values.size()); 
    280             ActionResult result = updateHierarchical(testAction, values.get(index)); 
     280            ActionResult result = updateLinkValue(testAction, values.get(index), valueType.getNestedValueType()); 
    281281            if (result.success && result.object != null) { 
    282282                values.add(index, result.object); 
    283283                return new ActionResult(true, values, result.duration); 
    284284            } 
    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; 
    294288            Object[] values = path.getElements(); 
    295289            int index = (int) (Math.random() * values.length); 
    296290            // 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()); 
    298292            if (result.success && result.object != null) { 
    299293                values[index] = result.object; 
     
    302296            return result; 
    303297        } else { 
    304             return updateLink(testAction, (Link)value); 
     298            return updateLink(testAction, (Link) value); 
    305299        } 
    306300    } 
Note: See TracChangeset for help on using the changeset viewer.