package water;

import org.junit.BeforeClass;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;

import static org.junit.Assert.*;

public class TCPReceiverThreadTest extends TestUtil {

  @BeforeClass()
  public static void setup() {
    stall_till_cloudsize(1);
  }

  @Test
  public void testDontShutdownOnGarbageRequests() throws Exception {
    NodeLocalEventCollectingListener ext = NodeLocalEventCollectingListener.getFreshInstance(); 

    // make a bogus request to our H2O PORT (NOT the API PORT!!!)
    // using HTTP is just a cheap trick to send some garbage data that H2O won't recognize
    URL apiURL = new URL("http:/" + H2O.SELF_ADDRESS + ":" + H2O.H2O_PORT + "/");
    try (InputStream is = apiURL.openStream()) {
      assertNull(is); // should never happen
    } catch (IOException e) {
      assertEquals("Connection reset", e.getMessage());
    }

    ArrayList<Object[]> protocolFailure = ext.getData("protocol-failure");
    assertEquals(1, protocolFailure.size());
    assertArrayEquals(new Object[]{"handshake"}, protocolFailure.get(0));
  }

}

@@ -889,57 +889,158 @@
     
-assertEquals(%22Connection reset%22, e.getMessage());
+String m = e.getMessage();%0A      if (!m.equals(%22Connection reset%22) && !m.equals(%22Connection refused (Connection refused)%22)) %7B%0A        throw e;%0A      %7D
 %0A   

Fix expected message in TCPReceiverThreadTest (#3436)