Changeset 5685 for DASISH


Ignore:
Timestamp:
09/29/14 15:27:57 (10 years ago)
Author:
olhsha@mpi.nl
Message:

multithread stress test java AnnotationResource? getAnnootation(x)

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r5684 r5685  
    3333import eu.dasish.annotation.schema.ResponseBody;
    3434import java.io.IOException;
     35import java.util.ArrayList;
    3536import java.util.Arrays;
    3637import java.util.HashMap;
    3738import java.util.List;
    3839import java.util.Map;
     40import java.util.Random;
    3941import java.util.UUID;
    4042import javax.servlet.http.HttpServletRequest;
     
    177179        }
    178180    }
     181   
     182    @GET
     183    @Produces(MediaType.TEXT_PLAIN)
     184    @Path("stressTest")
     185    @Transactional(readOnly = true)
     186    public String getAnnotationsMultithread(@QueryParam("n") int n) throws IOException, NotInDataBaseException {
     187        Number remotePrincipalID = this.getPrincipalID();
     188        if (remotePrincipalID == null) {
     189            return "You are not logged in";
     190        }
     191        String typeOfAccount = dbDispatcher.getTypeOfPrincipalAccount(remotePrincipalID);
     192        if (typeOfAccount.equals(admin) || typeOfAccount.equals(DebugResource.developer)) {
     193           
     194            System.out.print("Preparing the data: getting the list of all annotations, picking up "+n+" of them randomly, and initializing threads");           
     195            final List<Number> annotationIDs = dbDispatcher.getFilteredAnnotationIDs(null, null, null, remotePrincipalID, "read", null, null, null);
     196            final int size = annotationIDs.size();
     197            List<GetThread> threads = new ArrayList<GetThread>(n);
     198            Random rand = new Random();
     199            for (int i=0; i<n; i++) {
     200               int r = rand.nextInt(size);
     201               String annotationExternalId = dbDispatcher.getResourceExternalIdentifier(annotationIDs.get(r), Resource.ANNOTATION).toString();
     202               GetThread thread = new GetThread(this, annotationExternalId);
     203               threads.add(thread);           
     204            }
     205                       
     206            System.out.print("Running on getAnnotation(id) (no serialized output is shown to save time) on randomly selected annotation ids.");
     207            for (int i=0; i<n; i++) {
     208               threads.get(i).run();           
     209            }
     210           
     211            return "Stress-tested annotationrResource's getAnnotation(xxx): ok";
     212        } else {
     213            httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
     214            return "You cannot enjoy this priviledged service because youe are neither admin nor developer. Ask the admin for more priviledges";
     215        }
     216    }
     217   
     218   
    179219// TODO Unit test   
    180220
     
    605645        }
    606646    }
     647   
     648   
    607649}
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/DebugResource.java

    r5468 r5685  
    2222import eu.dasish.annotation.backend.NotInDataBaseException;
    2323import eu.dasish.annotation.backend.Resource;
     24import eu.dasish.annotation.schema.AnnotationInfo;
    2425import eu.dasish.annotation.schema.AnnotationInfoList;
    2526import eu.dasish.annotation.schema.ObjectFactory;
     
    2930import java.util.ArrayList;
    3031import java.util.List;
     32import java.util.Random;
    3133import java.util.UUID;
    3234import javax.servlet.http.HttpServletResponse;
     
    4951public class DebugResource extends ResourceResource {
    5052
    51     private final String developer = "developer";
     53    public static final String developer = "developer";
    5254   
    5355   
     
    7880        }
    7981    }
     82   
     83   
    8084
    8185    @GET
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/webapp/index.jsp

    r5675 r5685  
    7676        <br>
    7777        <b>Debugging URI's (only for developers)</b><br>
     78        GET <a href="api/annotations/stressTest?n=33">api/annotations/stressTest?n=33</a> <br>
    7879        GET <a href="api/debug/remoteID">api/debug/remoteID</a> <br>
    7980        GET <a href="api/debug/uuid">api/debug/uuid</a> (random uuid) <br>
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r5393 r5685  
    411411
    412412
    413 
    414413        JAXBElement<ResponseBody> result = annotationResource.updateAnnotationHeadline("00000000-0000-0000-0000-000000000021", newHeadline);
    415414        Annotation newAnnotation = result.getValue().getAnnotation();
    416415        assertEquals("new Headline", newAnnotation.getHeadline());
    417416    }
     417   
     418     
     419           
    418420}
Note: See TracChangeset for help on using the changeset viewer.