<commit_before>/**
 * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
 * 
 * Please see distribution for license.
 */
package com.opengamma.engine.view.calcnode;

import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.Test;
import com.opengamma.engine.test.TestCalculationNode;
import com.opengamma.util.test.Timeout;

/**
 * Tests the LocalNodeJobInvoker class
 */
@Test
public class LocalNodeJobInvokerTest implements JobInvokerRegister {

  private static final long TIMEOUT = Timeout.standardTimeoutMillis ();

  private JobInvoker _invoker;

  public void addNodeWithCallbackPending() {
    final LocalNodeJobInvoker invoker = new LocalNodeJobInvoker();
    _invoker = null;
    assertFalse (invoker.notifyWhenAvailable(this));
    assertNull(_invoker);
    invoker.addNode(new TestCalculationNode());
    assertEquals(invoker, _invoker);
  }

  public void addCallbackWithNodePending() {
    final LocalNodeJobInvoker invoker = new LocalNodeJobInvoker();
    _invoker = null;
    invoker.addNode(new TestCalculationNode());
    assertTrue (invoker.notifyWhenAvailable(this));
    assertNull(_invoker);
  }

  @Override
  public void registerJobInvoker(final JobInvoker invoker) {
    _invoker = invoker;
  }

  public void invokeWithNoNodes() {
    final LocalNodeJobInvoker invoker = new LocalNodeJobInvoker();
    final TestJobInvocationReceiver receiver = new TestJobInvocationReceiver();
    assertFalse(invoker.invoke(JobDispatcherTest.createTestJob(), receiver));
    assertNull(receiver.getCompletionResult());
  }

  public void invokeWithOneNode() {
    final LocalNodeJobInvoker invoker = new LocalNodeJobInvoker(new TestCalculationNode());
    final TestJobInvocationReceiver receiver = new TestJobInvocationReceiver();
    final CalculationJob job = JobDispatcherTest.createTestJob();
    assertTrue(invoker.invoke(job, receiver));
    final CalculationJobResult jobResult = receiver.waitForCompletionResult(TIMEOUT);
    assertNotNull(jobResult);
    assertEquals(job.getSpecification(), jobResult.getSpecification());
  }

}<commit_msg>[DVI-164] Move to TestNG, fix test<commit_after>/**
 * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
 * 
 * Please see distribution for license.
 */
package com.opengamma.engine.view.calcnode;

import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertTrue;

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.opengamma.engine.test.TestCalculationNode;
import com.opengamma.util.test.Timeout;

/**
 * Tests the LocalNodeJobInvoker class
 */
@Test
public class LocalNodeJobInvokerTest {

  private static final long TIMEOUT = Timeout.standardTimeoutMillis();

  private JobInvoker _invoker;
  private Register _register;

  @BeforeMethod
  public void setUp() {
    _invoker = null;
    _register = new Register();
  }

  public void testAddNodeWithCallbackPending() {
    final LocalNodeJobInvoker invoker = new LocalNodeJobInvoker();
    _invoker = null;
    assertFalse(invoker.notifyWhenAvailable(_register));
    assertNull(_invoker);
    invoker.addNode(new TestCalculationNode());
    assertEquals(invoker, _invoker);
  }

  public void testAddCallbackWithNodePending() {
    final LocalNodeJobInvoker invoker = new LocalNodeJobInvoker();
    _invoker = null;
    invoker.addNode(new TestCalculationNode());
    assertTrue(invoker.notifyWhenAvailable(_register));
    assertNull(_invoker);
  }

  public void testInvokeWithNoNodes() {
    final LocalNodeJobInvoker invoker = new LocalNodeJobInvoker();
    final TestJobInvocationReceiver receiver = new TestJobInvocationReceiver();
    assertFalse(invoker.invoke(JobDispatcherTest.createTestJob(), receiver));
    assertNull(receiver.getCompletionResult());
  }

  public void testInvokeWithOneNode() {
    final LocalNodeJobInvoker invoker = new LocalNodeJobInvoker(new TestCalculationNode());
    final TestJobInvocationReceiver receiver = new TestJobInvocationReceiver();
    final CalculationJob job = JobDispatcherTest.createTestJob();
    assertTrue(invoker.invoke(job, receiver));
    final CalculationJobResult jobResult = receiver.waitForCompletionResult(TIMEOUT);
    assertNotNull(jobResult);
    assertEquals(job.getSpecification(), jobResult.getSpecification());
  }

  class Register implements JobInvokerRegister {
    @Override
    public void registerJobInvoker(final JobInvoker invoker) {
      _invoker = invoker;
    }
  }
}
{'fraction_non_alphanumeric': 0.0876510342002867, 'fraction_numerical': 0.002252713495801761, 'mean_word_length': 5.2615384615384615, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6207630', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1361, 'n_words': 307}