Search in sources :

Example 11 with AuditCommand

use of org.asqatasun.service.command.AuditCommand in project Asqatasun by Asqatasun.

the class AuditServiceThreadQueueImplTest method testAddPageAuditWithConcurrentAccessAndMaxSizeReached.

/**
     * Test of addPageAudit method, of class AuditServiceThreadQueueImpl.
     */
public void testAddPageAuditWithConcurrentAccessAndMaxSizeReached() {
    System.out.println("addPageAuditWithConcurrentAccessAndMaxSizeReached");
    int numberOfSimultaneousRequestedCommand = 1000;
    // the tested instance
    AuditServiceThreadQueueImpl instance = new AuditServiceThreadQueueImpl();
    Collection<AuditCommand> auditCommands = new ArrayList<AuditCommand>();
    for (int i = 0; i < numberOfSimultaneousRequestedCommand; i++) {
        AuditCommand auditCommand = EasyMock.createMock(AuditCommand.class);
        auditCommands.add(auditCommand);
    }
    // Create the mock instance
    AuditServiceThread auditServiceThread = createMockAuditServiceThreadWithFireCompleted(instance, auditCommands.size());
    // Create the mock instance
    AuditServiceThreadFactory auditServiceThreadFactory = createMockAuditServiceThreadFactoryWithMultipleCommand(auditCommands, auditServiceThread);
    instance.setAuditServiceThreadFactory(auditServiceThreadFactory);
    for (AuditCommand auditCommand : auditCommands) {
        instance.addPageAudit(auditCommand);
    }
    // an unexpected error
    try {
        Thread.sleep(5);
    } catch (InterruptedException ex) {
        Logger.getLogger(AuditServiceThreadQueueImplTest.class.getName()).log(Level.SEVERE, null, ex);
    }
    for (int i = 0; i < numberOfSimultaneousRequestedCommand; i++) {
        instance.auditCompleted(auditServiceThread);
        // sleep for last audit blocked in queue be executed
        try {
            Thread.sleep(5);
        } catch (InterruptedException ex) {
            Logger.getLogger(AuditServiceThreadQueueImplTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    // sleep for last audit blocked in queue be executed
    try {
        Thread.sleep(10);
    } catch (InterruptedException ex) {
        Logger.getLogger(AuditServiceThreadQueueImplTest.class.getName()).log(Level.SEVERE, null, ex);
    }
    // Verify behavior.
    EasyMock.verify(auditServiceThreadFactory);
    EasyMock.verify(auditServiceThread);
}
Also used : ArrayList(java.util.ArrayList) AuditCommand(org.asqatasun.service.command.AuditCommand)

Example 12 with AuditCommand

use of org.asqatasun.service.command.AuditCommand in project Asqatasun by Asqatasun.

the class AuditServiceImpl method loadScenario.

@Override
public Audit loadScenario(Audit audit) {
    AuditCommand auditCommand = auditCommandFactory.create(null, null, true);
    auditCommand.setAudit(audit);
    return audit;
}
Also used : AuditCommand(org.asqatasun.service.command.AuditCommand)

Example 13 with AuditCommand

use of org.asqatasun.service.command.AuditCommand in project Asqatasun by Asqatasun.

the class AuditServiceThreadQueueImpl method processAuditWaitQueue.

/**
     *
     * @param auditWaitQueue
     * @param auditExecutionList
     * @param auditExecutionListMax
     * @return
     */
private synchronized void processAuditWaitQueue(Queue<AuditCommand> auditWaitQueue, List<AuditServiceThread> auditExecutionList, int auditExecutionListMax) {
    if (auditWaitQueue.peek() == null) {
        return;
    }
    if (auditExecutionList.size() < auditExecutionListMax) {
        AuditCommand auditCommand = auditWaitQueue.poll();
        LOGGER.debug("auditCommand polled");
        AuditServiceThread auditServiceThread = auditServiceThreadFactory.create(auditCommand);
        LOGGER.debug("AuditServiceThread created from auditCommand");
        auditServiceThread.add(this);
        auditExecutionList.add(auditServiceThread);
        new Thread(auditServiceThread).start();
        LOGGER.debug("AuditServiceThread started");
    } else {
        LOGGER.debug("Execution requested but max simultaneous execution reached");
    }
}
Also used : AuditCommand(org.asqatasun.service.command.AuditCommand)

Example 14 with AuditCommand

use of org.asqatasun.service.command.AuditCommand in project Asqatasun by Asqatasun.

the class AuditServiceImpl method auditScenario.

@Override
public Audit auditScenario(String scenarioName, String scenario, Set<Parameter> paramSet) {
    Logger.getLogger(this.getClass()).debug("auditScenario");
    AuditCommand auditCommand = auditCommandFactory.create(scenarioName, scenario, paramSet);
    auditServiceThreadQueue.addScenarioAudit(auditCommand);
    return auditCommand.getAudit();
}
Also used : AuditCommand(org.asqatasun.service.command.AuditCommand)

Example 15 with AuditCommand

use of org.asqatasun.service.command.AuditCommand in project Asqatasun by Asqatasun.

the class AuditServiceImpl method auditSite.

@Override
public Audit auditSite(String siteUrl, List<String> pageUrlList, Set<Parameter> paramSet) {
    Logger.getLogger(this.getClass()).debug("auditGroupOfPages");
    AuditCommand auditCommand = auditCommandFactory.create(siteUrl, pageUrlList, paramSet);
    auditServiceThreadQueue.addPageAudit(auditCommand);
    return auditCommand.getAudit();
}
Also used : AuditCommand(org.asqatasun.service.command.AuditCommand)

Aggregations

AuditCommand (org.asqatasun.service.command.AuditCommand)31 Audit (org.asqatasun.entity.audit.Audit)7 AuditCommandFactory (org.asqatasun.service.command.factory.AuditCommandFactory)5 Parameter (org.asqatasun.entity.parameterization.Parameter)4 ArrayList (java.util.ArrayList)1