/**
 * Copyright (C) 2011 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.web.analytics.push;

import static org.mockito.Mockito.mock;

import java.util.Collections;

import org.testng.annotations.Test;

import com.opengamma.DataNotFoundException;
import com.opengamma.core.change.ChangeManager;
import com.opengamma.core.change.ChangeProvider;
import com.opengamma.id.UniqueId;
import com.opengamma.web.analytics.rest.MasterType;

public class ConnectionManagerImplTest {

  @Test(expectedExceptions = DataNotFoundException.class)
  public void timeout() throws InterruptedException {
    // update manager with non-default short timeouts
    MasterChangeManager masterChangeManager = new MasterChangeManager(Collections.<MasterType, ChangeProvider>emptyMap());
    ConnectionManagerImpl connectionManager = new ConnectionManagerImpl(mock(ChangeManager.class),
                                                                        masterChangeManager,
                                                                        new LongPollingConnectionManager(),
                                                                        1000,
                                                                        500);
    // connection that will be allowed to time out
    String clientId = connectionManager.clientConnected("userId");
    // should complete normally
    connectionManager.subscribe("userId", clientId, UniqueId.of("Tst", "123"), "url");
    // wait until timeout
    Thread.sleep(2000);
    // connection should have timed out, exception will be thrown because clientId is unknown
    connectionManager.subscribe("userId", clientId, UniqueId.of("Tst", "1234"), "url");
  }
}

@@ -458,16 +458,56 @@
 iqueId;%0A
+import com.opengamma.util.test.Timeout;%0A
 import c
@@ -763,16 +763,22 @@
 uts%0A    
+final 
 MasterCh
@@ -892,16 +892,22 @@
 ));%0A    
+final 
 Connecti
@@ -1270,12 +1270,43 @@
     
-1000
+Timeout.standardTimeoutMillis() / 2
 ,%0A  
@@ -1379,11 +1379,43 @@
     
-500
+Timeout.standardTimeoutMillis() / 4
 );%0A 
@@ -1468,16 +1468,22 @@
 out%0A    
+final 
 String c
@@ -1703,12 +1703,39 @@
 eep(
-2000
+Timeout.standardTimeoutMillis()
 );%0A 

Use a standard timeout.