Class SocketProxy

java.lang.Object
org.apache.solr.util.SocketProxy

public class SocketProxy extends Object
A TCP-level proxy used in tests to simulate network partitions. It listens on its own port and forwards all traffic to the target Jetty server. Key operations:
  • close() — drops all connections and stops accepting new ones (simulates connection refused)
  • pause() / goOn() — freezes all data flow while keeping sockets open (simulates a hung network)
  • reopen() — restores connectivity on the same port after a close()

The proxy sits in front of Jetty by design: the Jetty server and ZooKeeper heartbeats continue running normally while the proxy makes the node appear unreachable to clients. A Jetty Handler cannot achieve this because it requires a TCP connection to already exist.

Implementation note: each accepted connection creates a SocketProxy.Bridge backed by two SocketProxy.Bridge.Pump threads (one per direction), using blocking I/O borrowed from ActiveMQ.

TODO: Replace the blocking-I/O SocketProxy.Bridge.Pump threads with a NIO java.nio.channels.Selector-based implementation. The current model spawns 2 OS threads per connection; under test load with many concurrent connections this is wasteful, and the PUMP_SOCKET_TIMEOUT_MS timeout means threads linger for up to 100 s after connections are dropped. A single-selector loop would handle all connections with O(1) threads, as Jetty itself does internally.

  • Field Details

  • Constructor Details

  • Method Details

    • open

      public void open(URI uri) throws Exception
      Throws:
      Exception
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setReceiveBufferSize

      public void setReceiveBufferSize(int receiveBufferSize)
    • setTarget

      public void setTarget(URI tcpBrokerUri)
    • getListenPort

      public int getListenPort()
    • getUrl

      public URI getUrl()
    • close

      public void close()
    • halfClose

      public void halfClose()
    • waitUntilClosed

      public boolean waitUntilClosed(long timeoutSeconds) throws InterruptedException
      Throws:
      InterruptedException
    • reopen

      public void reopen()
    • pause

      public void pause()
    • goOn

      public void goOn()
    • isPauseAtStart

      public boolean isPauseAtStart()
    • setPauseAtStart

      public void setPauseAtStart(boolean pauseAtStart)
    • getAcceptBacklog

      public int getAcceptBacklog()
    • setAcceptBacklog

      public void setAcceptBacklog(int acceptBacklog)