Skip to content

Commit

Permalink
TcpDataWriter should use TcpInput class to attach to socket
Browse files Browse the repository at this point in the history
  • Loading branch information
pax95 authored and oscerd committed Jul 25, 2015
1 parent b170152 commit bcaddc1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Expand Up @@ -20,8 +20,9 @@
import java.net.Socket; import java.net.Socket;


import com.splunk.Args; import com.splunk.Args;
import com.splunk.Input;
import com.splunk.Service; import com.splunk.Service;
import com.splunk.TcpInput;

import org.apache.camel.component.splunk.SplunkEndpoint; import org.apache.camel.component.splunk.SplunkEndpoint;


public class TcpDataWriter extends SplunkDataWriter { public class TcpDataWriter extends SplunkDataWriter {
Expand All @@ -37,14 +38,13 @@ public void setPort(int port) {


@Override @Override
protected Socket createSocket(Service service) throws IOException { protected Socket createSocket(Service service) throws IOException {
Input input = service.getInputs().get(String.valueOf(port)); TcpInput input = (TcpInput)service.getInputs().get(String.valueOf(port));
if (input == null) { if (input == null) {
throw new RuntimeException("no input defined for port " + port); throw new RuntimeException("no input defined for port " + port);
} }
if (input.isDisabled()) { if (input.isDisabled()) {
throw new RuntimeException(String.format("input on port %d is disabled", port)); throw new RuntimeException(String.format("input on port %d is disabled", port));
} }
Socket socket = service.open(port); return input.attach();
return socket;
} }
} }
Expand Up @@ -23,13 +23,12 @@
import com.splunk.Args; import com.splunk.Args;
import com.splunk.Index; import com.splunk.Index;
import com.splunk.IndexCollection; import com.splunk.IndexCollection;
import com.splunk.Input;
import com.splunk.InputCollection; import com.splunk.InputCollection;
import com.splunk.Service; import com.splunk.Service;
import com.splunk.TcpInput;


import org.apache.camel.CamelContext; import org.apache.camel.CamelContext;


import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.isA; import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -69,8 +68,8 @@ private void mockSplunkWriterApi() {
when(service.getIndexes()).thenReturn(indexColl); when(service.getIndexes()).thenReturn(indexColl);
InputCollection inputCollection = mock(InputCollection.class); InputCollection inputCollection = mock(InputCollection.class);
when(service.getInputs()).thenReturn(inputCollection); when(service.getInputs()).thenReturn(inputCollection);
Input input = mock(Input.class); TcpInput input = mock(TcpInput.class);
when(service.open(anyInt())).thenReturn(socket); when(input.attach()).thenReturn(socket);
when(inputCollection.get(anyString())).thenReturn(input); when(inputCollection.get(anyString())).thenReturn(input);
when(indexColl.get(anyString())).thenReturn(index); when(indexColl.get(anyString())).thenReturn(index);
when(index.attach(isA(Args.class))).thenReturn(socket); when(index.attach(isA(Args.class))).thenReturn(socket);
Expand Down

0 comments on commit bcaddc1

Please sign in to comment.