Skip to content

Commit

Permalink
Replace useSsl with sslEnabled
Browse files Browse the repository at this point in the history
  • Loading branch information
komamitsu committed Mar 27, 2018
1 parent 7a8698f commit d0da017
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 48 deletions.
14 changes: 7 additions & 7 deletions src/main/java/org/komamitsu/fluency/Fluency.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private static Sender.Instantiator createBaseSenderConfig(Config config, String
throw new IllegalArgumentException("`port` should be specified when using heartbeat");
}

if (config != null && config.useSsl) {
if (config != null && config.sslEnabled) {
SSLSender.Config senderConfig = new SSLSender.Config();
if (host != null) {
senderConfig.setHost(host);
Expand Down Expand Up @@ -468,7 +468,7 @@ public static class Config

private SenderErrorHandler senderErrorHandler;

private boolean useSsl;
private boolean sslEnabled;

public Long getMaxBufferSize()
{
Expand Down Expand Up @@ -591,14 +591,14 @@ public Config setSenderErrorHandler(SenderErrorHandler senderErrorHandler)
return this;
}

public boolean getUseSsl()
public boolean isSslEnabled()
{
return useSsl;
return sslEnabled;
}

public Config setUseSsl(boolean useSsl)
public Config setSslEnabled(boolean sslEnabled)
{
this.useSsl = useSsl;
this.sslEnabled = sslEnabled;
return this;
}

Expand All @@ -617,7 +617,7 @@ public String toString()
", waitUntilFlusherTerminated=" + waitUntilFlusherTerminated +
", jvmHeapBufferMode=" + jvmHeapBufferMode +
", senderErrorHandler=" + senderErrorHandler +
", useSsl =" + useSsl +
", sslEnabled =" + sslEnabled +
'}';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@ public void onClose(Socket acceptSocket)
}
}

public AbstractFluentdServer(boolean useSsl)
public AbstractFluentdServer(boolean sslEnabled)
throws Exception
{
super(useSsl);
super(sslEnabled);
}

@Override
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/komamitsu/fluency/FluencyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void testDefaultFluencyWithSsl()
{
Fluency fluency = null;
try {
fluency = Fluency.defaultFluency(new Fluency.Config().setUseSsl(true));
fluency = Fluency.defaultFluency(new Fluency.Config().setSslEnabled(true));
assertDefaultBuffer(fluency.getBuffer());
assertDefaultFlusher(fluency.getFlusher());
assertDefaultSender(fluency.getFlusher().getSender(), "127.0.0.1", 24224, SSLSender.class);
Expand All @@ -195,7 +195,7 @@ public void testDefaultFluencyWithSslAndCustomPort()
{
Fluency fluency = null;
try {
fluency = Fluency.defaultFluency(54321, new Fluency.Config().setUseSsl(true));
fluency = Fluency.defaultFluency(54321, new Fluency.Config().setSslEnabled(true));
assertDefaultBuffer(fluency.getBuffer());
assertDefaultFlusher(fluency.getFlusher());
assertDefaultSender(fluency.getFlusher().getSender(), "127.0.0.1", 54321, SSLSender.class);
Expand All @@ -213,7 +213,7 @@ public void testDefaultFluencyWithSslAndCustomHostAndPort()
{
Fluency fluency = null;
try {
fluency = Fluency.defaultFluency("192.168.0.99", 54321, new Fluency.Config().setUseSsl(true));
fluency = Fluency.defaultFluency("192.168.0.99", 54321, new Fluency.Config().setSslEnabled(true));
assertDefaultBuffer(fluency.getBuffer());
assertDefaultFlusher(fluency.getFlusher());
assertDefaultSender(fluency.getFlusher().getSender(), "192.168.0.99", 54321, SSLSender.class);
Expand Down Expand Up @@ -334,7 +334,7 @@ public void testDefaultFluencyWithSslAndComplexConfig()

Fluency.Config config =
new Fluency.Config()
.setUseSsl(true)
.setSslEnabled(true)
.setFlushIntervalMillis(200)
.setMaxBufferSize(Long.MAX_VALUE)
.setBufferChunkInitialSize(7 * 1024 * 1024)
Expand Down
24 changes: 12 additions & 12 deletions src/test/java/org/komamitsu/fluency/FluencyTestWithMockServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static class Options
private final boolean closeInsteadOfFlush;
private final boolean ackResponse;
private final boolean smallBuffer;
private final boolean useSsl;
private final boolean sslEnabled;
private final EmitType emitType;

Options(
Expand All @@ -112,9 +112,9 @@ public static class Options
boolean closeInsteadOfFlush,
boolean ackResponse,
boolean smallBuffer,
boolean useSsl)
boolean sslEnabled)
{
this(failover, fileBackup, closeInsteadOfFlush, ackResponse, smallBuffer, useSsl, EmitType.MAP);
this(failover, fileBackup, closeInsteadOfFlush, ackResponse, smallBuffer, sslEnabled, EmitType.MAP);
}

Options(
Expand All @@ -123,15 +123,15 @@ public static class Options
boolean closeInsteadOfFlush,
boolean ackResponse,
boolean smallBuffer,
boolean useSsl,
boolean sslEnabled,
EmitType emitType)
{
this.failover = failover;
this.fileBackup = fileBackup;
this.closeInsteadOfFlush = closeInsteadOfFlush;
this.ackResponse = ackResponse;
this.smallBuffer = smallBuffer;
this.useSsl = useSsl;
this.sslEnabled = sslEnabled;
this.emitType = emitType;
}

Expand Down Expand Up @@ -162,7 +162,7 @@ public boolean equals(Object o)
if (smallBuffer != options.smallBuffer) {
return false;
}
if (useSsl != options.useSsl) {
if (sslEnabled != options.sslEnabled) {
return false;
}
return emitType == options.emitType;
Expand All @@ -176,7 +176,7 @@ public int hashCode()
result = 31 * result + (closeInsteadOfFlush ? 1 : 0);
result = 31 * result + (ackResponse ? 1 : 0);
result = 31 * result + (smallBuffer ? 1 : 0);
result = 31 * result + (useSsl ? 1 : 0);
result = 31 * result + (sslEnabled ? 1 : 0);
result = 31 * result + (emitType != null ? emitType.hashCode() : 0);
return result;
}
Expand All @@ -190,7 +190,7 @@ public String toString()
", closeInsteadOfFlush=" + closeInsteadOfFlush +
", ackResponse=" + ackResponse +
", smallBuffer=" + smallBuffer +
", useSsl=" + useSsl +
", sslEnabled=" + sslEnabled +
", emitType=" + emitType +
'}';
}
Expand Down Expand Up @@ -252,15 +252,15 @@ public Fluency generate(List<Integer> localPorts)
int fluentdPort = localPorts.get(0);
if (options.failover) {
int secondaryFluentdPort = localPorts.get(1);
if (options.useSsl) {
if (options.sslEnabled) {
sender = getDoubleSSLSender(fluentdPort, secondaryFluentdPort);
}
else {
sender = getDoubleTCPSender(fluentdPort, secondaryFluentdPort);
}
}
else {
if (options.useSsl) {
if (options.sslEnabled) {
sender = getSingleSSLSender(fluentdPort);
}
else {
Expand Down Expand Up @@ -292,10 +292,10 @@ private void testFluencyBase(final FluencyFactory fluencyFactory, final Options

final ArrayList<Integer> localPorts = new ArrayList<Integer>();

final MockFluentdServer fluentd = new MockFluentdServer(options.useSsl);
final MockFluentdServer fluentd = new MockFluentdServer(options.sslEnabled);
fluentd.start();

final MockFluentdServer secondaryFluentd = new MockFluentdServer(options.useSsl, fluentd);
final MockFluentdServer secondaryFluentd = new MockFluentdServer(options.sslEnabled, fluentd);
secondaryFluentd.start();

localPorts.add(fluentd.getLocalPort());
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/komamitsu/fluency/MockTCPServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public class MockTCPServer
private static final Logger LOG = LoggerFactory.getLogger(MockTCPServer.class);
private ExecutorService executorService;
private ServerTask serverTask;
private final boolean useSsl;
private final boolean sslEnabled;
private final AtomicLong lastEventTimeStampMilli = new AtomicLong();

public MockTCPServer(boolean useSsl)
public MockTCPServer(boolean sslEnabled)
{
this.useSsl = useSsl;
this.sslEnabled = sslEnabled;
}

public interface EventHandler
Expand Down Expand Up @@ -78,7 +78,7 @@ public Thread newThread(Runnable r)

if (serverTask == null) {
serverTask = new ServerTask(executorService, lastEventTimeStampMilli, getEventHandler(),
useSsl ? new SSLTestServerSocketFactory().create() : new ServerSocket());
sslEnabled ? new SSLTestServerSocketFactory().create() : new ServerSocket());
executorService.execute(serverTask);
}

Expand Down Expand Up @@ -109,7 +109,7 @@ public String toString()
{
return "MockTCPServer{" +
"serverTask=" + serverTask +
", useSsl=" + useSsl +
", sslEnabled=" + sslEnabled +
'}';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public static class Config
public final int concurrency;
@JsonProperty("wait_seconds")
public final int waitSeconds;
@JsonProperty("use_ssl")
public final boolean useSsl;
@JsonProperty("ssl_enabled")
public final boolean sslEnabled;

public Config(
@JsonProperty("host")
Expand All @@ -101,8 +101,8 @@ public Config(
Integer concurrency,
@JsonProperty("wait_seconds")
Integer waitSeconds,
@JsonProperty("use_ssl")
Boolean useSsl
@JsonProperty("ssl_enabled")
Boolean sslEnabled
)
{
this.host = host == null ? "127.0.0.1" : host;
Expand All @@ -116,7 +116,7 @@ public Config(
this.requests = requests == null ? 1000000 : requests;
this.concurrency = concurrency == null ? 4 : concurrency;
this.waitSeconds = waitSeconds == null ? 60 : waitSeconds;
this.useSsl = useSsl == null ? false : useSsl;
this.sslEnabled = sslEnabled == null ? false : sslEnabled;
}
}

Expand All @@ -141,7 +141,7 @@ public void testWithRealFluentd()
Fluency fluency = Fluency.defaultFluency(
config.port,
new Fluency.Config()
.setUseSsl(config.useSsl)
.setSslEnabled(config.sslEnabled)
);

Map<String, Object> data = new HashMap<String, Object>();
Expand Down Expand Up @@ -179,7 +179,7 @@ public void testWithRealMultipleFluentd()
*/
Fluency fluency = Fluency.defaultFluency(
Arrays.asList(new InetSocketAddress(config.port), new InetSocketAddress(config.anotherPort)),
new Fluency.Config().setUseSsl(config.useSsl).setAckResponseMode(true));
new Fluency.Config().setSslEnabled(config.sslEnabled).setAckResponseMode(true));

Map<String, Object> data = new HashMap<String, Object>();
data.put("name", "komamitsu");
Expand Down Expand Up @@ -212,7 +212,7 @@ public void testWithRealFluentdWithFileBackup()
new Fluency.Config()
// Fluency might use a lot of buffer for loaded backup files.
// So it'd better increase max buffer size
.setUseSsl(config.useSsl)
.setSslEnabled(config.sslEnabled)
.setMaxBufferSize(512 * 1024 * 1024L)
.setFileBackupDir(System.getProperty("java.io.tmpdir")));
Map<String, Object> data = new HashMap<String, Object>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public class MockMultiTCPServerWithMetrics
private ExecutorService executorService;
private DatagramChannel channel;

public MockMultiTCPServerWithMetrics(boolean useSsl)
public MockMultiTCPServerWithMetrics(boolean sslEnabled)
throws IOException
{
super(useSsl);
super(sslEnabled);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.komamitsu.fluency.MockTCPServer;
import org.komamitsu.fluency.util.Tuple;

import java.io.IOException;
import java.net.Socket;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
Expand Down Expand Up @@ -32,9 +31,9 @@ public void onClose(Socket acceptSocket)
}
};

public MockTCPServerWithMetrics(boolean useSsl)
public MockTCPServerWithMetrics(boolean sslEnabled)
{
super(useSsl);
super(sslEnabled);
}

@Override
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/komamitsu/fluency/sender/MultiSenderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,20 @@ public void testSSLSend()
testSend(true);
}

private void testSend(boolean useSsl)
private void testSend(boolean sslEnabled)
throws Exception
{
final MockMultiTCPServerWithMetrics server0 = new MockMultiTCPServerWithMetrics(useSsl);
final MockMultiTCPServerWithMetrics server0 = new MockMultiTCPServerWithMetrics(sslEnabled);
server0.start();
final MockMultiTCPServerWithMetrics server1 = new MockMultiTCPServerWithMetrics(useSsl);
final MockMultiTCPServerWithMetrics server1 = new MockMultiTCPServerWithMetrics(sslEnabled);
server1.start();

int concurency = 20;
final int reqNum = 5000;
final CountDownLatch latch = new CountDownLatch(concurency);

final MultiSender sender = new MultiSender.Config(
useSsl ?
sslEnabled ?
Arrays.<Sender.Instantiator>asList(
new SSLSender.Config()
.setPort(server0.getLocalPort())
Expand Down Expand Up @@ -238,7 +238,7 @@ public void run()
assertEquals(2, connectCount);
// This test doesn't use actual PackedForward format so that it can simply test MultiSender itself.
// But w/o ack responses, Sender can't detect dropped requests. So some margin for expected result is allowed here
long minExpectedRecvLen = ((long)(concurency - (useSsl ? 6 : 2)) * reqNum) * 10;
long minExpectedRecvLen = ((long)(concurency - (sslEnabled ? 6 : 2)) * reqNum) * 10;
long maxExpectedRecvLen = ((long)concurency * reqNum) * 10;
assertThat(recvLen, is(greaterThanOrEqualTo(minExpectedRecvLen)));
assertThat(recvLen, is(lessThanOrEqualTo(maxExpectedRecvLen)));
Expand Down

0 comments on commit d0da017

Please sign in to comment.