<commit_before>/**
 * Copyright (C) 2009 - 2010 by OpenGamma Inc.
 *
 * Please see distribution for license.
 */
package com.opengamma.engine.view.cache;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;

import org.fudgemsg.FudgeContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opengamma.engine.ComputationTargetSpecification;
import com.opengamma.engine.ComputationTargetType;
import com.opengamma.engine.value.ComputedValue;
import com.opengamma.engine.value.ValueRequirement;
import com.opengamma.engine.value.ValueSpecification;
import com.opengamma.id.UniqueIdentifier;
import com.opengamma.transport.socket.ServerSocketFudgeRequestDispatcher;
import com.opengamma.transport.socket.SocketFudgeRequestSender;
import com.opengamma.util.ThreadUtil;

/**
 * A test of the remote View Computation Cache Source infrastucture operating
 * over proper sockets.
 *
 */
public class ServerSocketRemoteViewComputationCacheTest {
  private static final Logger s_logger = LoggerFactory.getLogger(ServerSocketRemoteViewComputationCacheTest.class);
  // When attempting to fix ENG-100, set this constant to more than 1.
  private static final int NUM_THREADS = 5;
  private static final int NUM_LOOKUPS = 1000;
  private ViewComputationCacheSource _cacheSource;
  private ServerSocketFudgeRequestDispatcher _serverSocketDispatcher;
  private SocketFudgeRequestSender _socketSender;
  
  @Before
  public void setupCacheSource() throws UnknownHostException {
    InMemoryViewComputationCacheSource cache = new InMemoryViewComputationCacheSource (FudgeContext.GLOBAL_DEFAULT);
    ViewComputationCacheServer server = new ViewComputationCacheServer (cache);
    _serverSocketDispatcher = new ServerSocketFudgeRequestDispatcher(server);
    _serverSocketDispatcher.start();
    
    _socketSender = new SocketFudgeRequestSender();
    _socketSender.setInetAddress(InetAddress.getLocalHost());
    _socketSender.setPortNumber(_serverSocketDispatcher.getPortNumber());
    
    RemoteCacheClient client = new RemoteCacheClient(_socketSender);
    _cacheSource = new RemoteViewComputationCacheSource (client);
  }
  
  @After
  public void shutDown() {
    if(_socketSender != null) {
      _socketSender.stop();
    }
    if(_serverSocketDispatcher != null) {<commit_msg>[UTL-67] Changed the constructor of ServerSocketFudgeRequestDispatcher<commit_after>/**
 * Copyright (C) 2009 - 2010 by OpenGamma Inc.
 *
 * Please see distribution for license.
 */
package com.opengamma.engine.view.cache;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;

import org.fudgemsg.FudgeContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opengamma.engine.ComputationTargetSpecification;
import com.opengamma.engine.ComputationTargetType;
import com.opengamma.engine.value.ComputedValue;
import com.opengamma.engine.value.ValueRequirement;
import com.opengamma.engine.value.ValueSpecification;
import com.opengamma.id.UniqueIdentifier;
import com.opengamma.transport.socket.ServerSocketFudgeRequestDispatcher;
import com.opengamma.transport.socket.SocketFudgeRequestSender;
import com.opengamma.util.ThreadUtil;

/**
 * A test of the remote View Computation Cache Source infrastucture operating
 * over proper sockets.
 *
 */
public class ServerSocketRemoteViewComputationCacheTest {
  private static final Logger s_logger = LoggerFactory.getLogger(ServerSocketRemoteViewComputationCacheTest.class);
  private static final int NUM_THREADS = 5;
  private static final int NUM_LOOKUPS = 1000;
  private ViewComputationCacheSource _cacheSource;
  private ServerSocketFudgeRequestDispatcher _serverSocketDispatcher;
  private SocketFudgeRequestSender _socketSender;
  
  @Before
  public void setupCacheSource() throws UnknownHostException {
    InMemoryViewComputationCacheSource cache = new InMemoryViewComputationCacheSource (FudgeContext.GLOBAL_DEFAULT);
    ViewComputationCacheServer server = new ViewComputationCacheServer (cache);
    _serverSocketDispatcher = new ServerSocketFudgeRequestDispatcher(server, cache.getFudgeContext ());
    _serverSocketDispatcher.start();
    
    _socketSender = new SocketFudgeRequestSender();
    _socketSender.setInetAddress(InetAddress.getLocalHost());
    _socketSender.setPortNumber(_serverSocketDispatcher.getPortNumber());
    
    RemoteCacheClient client = new RemoteCacheClient(_socketSender);
    _cacheSource = new RemoteViewComputationCacheSource (client);
  }
  
  @After
  public void shutDown() {
    if(_socketSender != null) {
      _socketSender.stop();
    }
    if(_serverSocketDispatcher != null) {
{'fraction_non_alphanumeric': 0.07861271676300578, 'fraction_numerical': 0.006936416184971098, 'mean_word_length': 5.821287779237845, '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': '1798141', 'n_tokens_mistral': 1496, 'n_tokens_neox': 1442, 'n_words': 316}