Package com.opengamma.engine.calcnode

Examples of com.opengamma.engine.calcnode.JobDispatcher


  private static final Logger s_logger = LoggerFactory.getLogger(RemoteNodeJobInvokerTest.class);
  private static final FudgeContext s_fudgeContext = OpenGammaFudgeContext.getInstance();
  private static final long TIMEOUT = Timeout.standardTimeoutMillis();

  public void simpleInvocation() {
    final JobDispatcher jobDispatcher = new JobDispatcher();
    final Ready initialMessage = new Ready(1, "Test");
    final DirectFudgeConnection conduit = new DirectFudgeConnection(s_fudgeContext);
    final RemoteNodeJobInvoker jobInvoker = new RemoteNodeJobInvoker(Executors.newCachedThreadPool(), initialMessage, conduit.getEnd1(), new InMemoryIdentifierMap(), new FunctionCosts(),
        new DummyFunctionBlacklistQuery(), new DummyFunctionBlacklistMaintainer());
    jobDispatcher.registerJobInvoker(jobInvoker);
    final TestJobResultReceiver resultReceiver = new TestJobResultReceiver();
    final FudgeConnection remoteNode = conduit.getEnd2();
    remoteNode.setFudgeMessageReceiver(new FudgeMessageReceiver() {
      @Override
      public void messageReceived(FudgeContext fudgeContext, FudgeMsgEnvelope msgEnvelope) {
        final FudgeDeserializer dcontext = new FudgeDeserializer(fudgeContext);
        s_logger.debug("message = {}", msgEnvelope.getMessage());
        final RemoteCalcNodeMessage message = dcontext.fudgeMsgToObject(RemoteCalcNodeMessage.class, msgEnvelope.getMessage());
        assertNotNull(message);
        s_logger.debug("request = {}", message);
        assertTrue(message instanceof Execute);
        final Execute job = (Execute) message;
        final Result result = new Result(JobDispatcherTest.createTestJobResult(job.getJob().getSpecification(), 0, "Test"));
        final FudgeSerializer scontext = new FudgeSerializer(fudgeContext);
        remoteNode.getFudgeMessageSender().send(FudgeSerializer.addClassHeader(scontext.objectToFudgeMsg(result), result.getClass(), RemoteCalcNodeMessage.class));
      }
    });
    jobDispatcher.dispatchJob(JobDispatcherTest.createTestJob(), resultReceiver);
    assertNotNull(resultReceiver.waitForResult(TIMEOUT));
  }
View Full Code Here


    jobDispatcher.dispatchJob(JobDispatcherTest.createTestJob(), resultReceiver);
    assertNotNull(resultReceiver.waitForResult(TIMEOUT));
  }

  public void saturate() {
    final JobDispatcher jobDispatcher = new JobDispatcher();
    final Ready initialMessage = new Ready(3, "Test");
    final DirectFudgeConnection conduit = new DirectFudgeConnection(s_fudgeContext);
    final RemoteNodeJobInvoker jobInvoker = new RemoteNodeJobInvoker(Executors.newCachedThreadPool(), initialMessage, conduit.getEnd1(), new InMemoryIdentifierMap(), new FunctionCosts(),
        new DummyFunctionBlacklistQuery(), new DummyFunctionBlacklistMaintainer());
    jobDispatcher.registerJobInvoker(jobInvoker);
    final FudgeConnection remoteNode = conduit.getEnd2();
    final Random rnd = new Random();
    remoteNode.setFudgeMessageReceiver(new FudgeMessageReceiver() {
      @Override
      public void messageReceived(FudgeContext fudgeContext, FudgeMsgEnvelope msgEnvelope) {
        final FudgeDeserializer dcontext = new FudgeDeserializer(fudgeContext);
        final RemoteCalcNodeMessage message = dcontext.fudgeMsgToObject(RemoteCalcNodeMessage.class, msgEnvelope.getMessage());
        assertNotNull(message);
        assertTrue(message instanceof Execute);
        final Execute job = (Execute) message;
        try {
          Thread.sleep(rnd.nextInt(30));
        } catch (InterruptedException e) {
        }
        final Result result = new Result(JobDispatcherTest.createTestJobResult(job.getJob().getSpecification(), 0, "Test"));
        final FudgeSerializer scontext = new FudgeSerializer(fudgeContext);
        remoteNode.getFudgeMessageSender().send(FudgeSerializer.addClassHeader(scontext.objectToFudgeMsg(result), result.getClass(), RemoteCalcNodeMessage.class));
      }
    });
    final TestJobResultReceiver[] resultReceivers = new TestJobResultReceiver[100];
    for (int i = 0; i < resultReceivers.length; i++) {
      resultReceivers[i] = new TestJobResultReceiver();
      jobDispatcher.dispatchJob(JobDispatcherTest.createTestJob(), resultReceivers[i]);
    }
    for (int i = 0; i < resultReceivers.length; i++) {
      assertNotNull(resultReceivers[i].waitForResult(TIMEOUT));
    }
  }
View Full Code Here

    final ThreadLocalLogEventListener threadLocalLogListener = new ThreadLocalLogEventListener();
    LogBridge.getInstance().addListener(threadLocalLogListener);
    final SimpleCalculationNode localCalcNode = new SimpleCalculationNode(cacheSource, compiledFunctions, functionExecutionContext, "node", Executors.newCachedThreadPool(),
        new DiscardingInvocationStatisticsGatherer(), new CalculationNodeLogEventListener(threadLocalLogListener));
    final LocalNodeJobInvoker jobInvoker = new LocalNodeJobInvoker(localCalcNode);
    vpFactBean.setComputationJobDispatcher(new JobDispatcher(jobInvoker));
    vpFactBean.setFunctionResolver(generateFunctionResolver(compiledFunctions));
    vpFactBean.setViewResultListenerFactory(_viewResultListenerFactory);
    _viewProcessor = (ViewProcessorImpl) vpFactBean.createObject();
  }
View Full Code Here

  private static CalculationJobSpecification createJobSpecification() {
    return new CalculationJobSpecification(UniqueId.of("Cycle", "1"), "Default", Instant.now(), JobIdSource.getId());
  }

  public void testStandardJob_createWatchedJob_singleItem() {
    final JobDispatcher dispatcher = new JobDispatcher();
    final FunctionBlacklistMaintainer blacklist = Mockito.mock(FunctionBlacklistMaintainer.class);
    dispatcher.setFunctionBlacklistMaintainer(blacklist);
    final CalculationJob job = new CalculationJob(createJobSpecification(), 0, VersionCorrection.LATEST, null, Arrays.asList(JOB_ITEM_A), CacheSelectHint.allShared());
    final StandardJob standard = new StandardJob(dispatcher, job, Mockito.mock(JobResultReceiver.class));
    final WatchedJob watched = standard.createWatchedJob();
    assertNull(watched);
    Mockito.verify(blacklist).failedJobItem(JOB_ITEM_A);
View Full Code Here

    assertNull(watched);
    Mockito.verify(blacklist).failedJobItem(JOB_ITEM_A);
  }

  public void testStandardJob_createWatchedJob_noTail() {
    final JobDispatcher dispatcher = new JobDispatcher();
    final CalculationJob job = new CalculationJob(createJobSpecification(), 0, VersionCorrection.LATEST, null, Arrays.asList(JOB_ITEM_AB, JOB_ITEM_BC), CacheSelectHint.allShared());
    final StandardJob standard = new StandardJob(dispatcher, job, Mockito.mock(JobResultReceiver.class));
    final WatchedJob watched = standard.createWatchedJob();
    assertTrue(watched instanceof WatchedJob.Whole);
    watched.getJob().equals(job);
View Full Code Here

    assertTrue(watched instanceof WatchedJob.Whole);
    watched.getJob().equals(job);
  }

  public void testStandardJob_createWatchedJob_rewrite() {
    final JobDispatcher dispatcher = new JobDispatcher();
    final CalculationJob job1 = new CalculationJob(createJobSpecification(), 0, VersionCorrection.LATEST, null, Arrays.asList(JOB_ITEM_AB), CacheSelectHint.privateValues(Arrays.asList(VS_B)));
    final CalculationJob job2 = new CalculationJob(createJobSpecification(), 0, VersionCorrection.LATEST, new long[] {job1.getSpecification().getJobId() }, Arrays.asList(JOB_ITEM_BC),
        CacheSelectHint.privateValues(Arrays.asList(VS_B)));
    job1.addTail(job2);
    final StandardJob standard = new StandardJob(dispatcher, job1, Mockito.mock(JobResultReceiver.class));
View Full Code Here

    final CalculationJob job4 = new CalculationJob(createJobSpecification(), 0, VersionCorrection.LATEST, new long[] {job2.getSpecification().getJobId(), job3.getSpecification().getJobId() },
        Arrays.asList(JOB_ITEM_BCD), CacheSelectHint.allShared());
    job3.addTail(job4);
    final JobResultReceiver receiver = Mockito.mock(JobResultReceiver.class);
    final Queue<DispatchableJob> dispatched = new LinkedList<DispatchableJob>();
    final JobDispatcher dispatcher = new JobDispatcher() {
      @Override
      protected void dispatchJobImpl(final DispatchableJob job) {
        dispatched.add(job);
      }
    };
View Full Code Here

    Mockito.verify(receiver).resultReceived(result4);
    Mockito.reset();
  }

  public void testWatchedJob_prepareRetryJob_singleItem() {
    final JobDispatcher dispatcher = new JobDispatcher();
    final FunctionBlacklistMaintainer blacklist = Mockito.mock(FunctionBlacklistMaintainer.class);
    dispatcher.setFunctionBlacklistMaintainer(blacklist);
    final CalculationJob job = new CalculationJob(createJobSpecification(), 0, VersionCorrection.LATEST, null, Arrays.asList(JOB_ITEM_A), CacheSelectHint.allShared());
    final JobResultReceiver receiver = Mockito.mock(JobResultReceiver.class);
    final StandardJob standard = new StandardJob(dispatcher, job, receiver);
    final WatchedJob watched = new WatchedJob.Whole(standard, job, receiver);
    watched.prepareRetryJob(null);
View Full Code Here

    Mockito.verify(blacklist).failedJobItem(JOB_ITEM_A);
  }

  public void testWatchedJob_prepareRetryJob_split_one() {
    final Queue<DispatchableJob> dispatched = new LinkedList<DispatchableJob>();
    final JobDispatcher dispatcher = new JobDispatcher() {
      @Override
      protected void dispatchJobImpl(final DispatchableJob job) {
        dispatched.add(job);
      }
    };
View Full Code Here

    assertTrue(job2.getSpecification().getJobId() == job.getSpecification().getJobId());
  }

  public void testWatchedJob_prepareRetryJob_split_two() {
    final Queue<DispatchableJob> dispatched = new LinkedList<DispatchableJob>();
    final JobDispatcher dispatcher = new JobDispatcher() {
      @Override
      protected void dispatchJobImpl(final DispatchableJob job) {
        dispatched.add(job);
      }
    };
View Full Code Here

TOP

Related Classes of com.opengamma.engine.calcnode.JobDispatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.