Skip to content

Commit d0f8768

Browse files
author
blackopsdev
committed
merge resloved
2 parents 6977f3a + ad5e226 commit d0f8768

File tree

6 files changed

+44
-24
lines changed

6 files changed

+44
-24
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>com.stackify</groupId>
55
<artifactId>stackify-api-common</artifactId>
6-
<version>1.0.10-SNAPSHOT</version>
6+
<version>1.0.11-SNAPSHOT</version>
77

88
<name>Stackify API Common</name>
99
<description>Stackify API Common</description>

src/main/java/com/stackify/api/common/log/LogBackgroundServiceScheduler.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,7 @@
2727
* @author Eric Martin
2828
*/
2929
public class LogBackgroundServiceScheduler extends CustomScheduler {
30-
31-
/**
32-
* One tenth of a second (milliseconds)
33-
*/
34-
private static final long ONE_TENTH_OF_A_SECOND = 100;
35-
30+
3631
/**
3732
* One second (milliseconds)
3833
*/
@@ -78,9 +73,9 @@ public void update(final int numSent) {
7873
if (100 <= numSent) {
7974

8075
// messages are coming in quickly so decrease our delay
81-
// minimum delay is 1/10 of a second
76+
// minimum delay is 1 second
8277

83-
scheduleDelay = Math.max(Math.round(scheduleDelay / 2.0), ONE_TENTH_OF_A_SECOND);
78+
scheduleDelay = Math.max(Math.round(scheduleDelay / 2.0), ONE_SECOND);
8479

8580
} else if (numSent < 10) {
8681

src/main/java/com/stackify/api/common/log/LogCollector.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
*/
3939
public class LogCollector {
4040

41+
/**
42+
* Max batch size of log messages to be sent in a single request
43+
*/
44+
private static final int MAX_BATCH = 100;
45+
4146
/**
4247
* The logger (project) name
4348
*/
@@ -56,7 +61,7 @@ public class LogCollector {
5661
/**
5762
* The queue of objects to be transmitted
5863
*/
59-
private final Queue<LogMsg> queue = Queues.synchronizedQueue(EvictingQueue.<LogMsg>create(1000));
64+
private final Queue<LogMsg> queue = Queues.synchronizedQueue(EvictingQueue.<LogMsg>create(10000));
6065

6166
/**
6267
* Constructor
@@ -100,15 +105,15 @@ public int flush(final LogSender sender) throws IOException, HttpException {
100105
while (numSent < maxToSend) {
101106

102107
// get the next batch of messages
103-
int batchSize = Math.min(maxToSend - numSent, 20);
108+
int batchSize = Math.min(maxToSend - numSent, MAX_BATCH);
104109

105110
List<LogMsg> batch = Lists.newArrayListWithCapacity(batchSize);
106111

107112
for (int i = 0; i < batchSize; ++i) {
108113
batch.add(queue.remove());
109114
}
110115

111-
// build the log message group testAddAndFlushrecord
116+
// build the log message group
112117
LogMsgGroup group = createLogMessageGroup(batch, logger, envDetail, appIdentity);
113118

114119
// send the batch to Stackify

src/test/java/com/stackify/api/common/ApiConfigurationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void testBuilder() {
5454
Assert.assertEquals(environment, apiConfig.getEnvironment());
5555
Assert.assertEquals(envDetail, apiConfig.getEnvDetail());
5656

57-
Assert.assertNotNull(envDetail.toString());
57+
Assert.assertNotNull(apiConfig.toString());
5858
}
5959

6060
/**

src/test/java/com/stackify/api/common/http/HttpClientTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,33 @@ public void testPostWithHttpError() throws Exception {
9292

9393
httpClient.post("path", "hello".getBytes());
9494
}
95+
96+
/**
97+
* testPostWithGzip
98+
* @throws Exception
99+
*/
100+
@Test
101+
public void testPostWithGzip() throws Exception {
102+
103+
URL url = PowerMockito.mock(URL.class);
104+
PowerMockito.whenNew(URL.class).withArguments(Mockito.anyString()).thenReturn(url);
105+
106+
HttpURLConnection connection = PowerMockito.mock(HttpURLConnection.class);
107+
108+
PowerMockito.when(url.openConnection()).thenReturn(connection);
109+
110+
ByteArrayOutputStream postBody = new ByteArrayOutputStream();
111+
PowerMockito.when(connection.getOutputStream()).thenReturn(postBody);
112+
113+
ByteArrayInputStream contents = new ByteArrayInputStream("world".getBytes());
114+
PowerMockito.when(connection.getInputStream()).thenReturn(contents);
115+
PowerMockito.when(connection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
116+
117+
HttpClient httpClient = new HttpClient(Mockito.mock(ApiConfiguration.class));
118+
119+
String world = httpClient.post("path", "hello".getBytes(), true);
120+
121+
Assert.assertNotNull(world);
122+
Assert.assertEquals("world", world);
123+
}
95124
}

src/test/java/com/stackify/api/common/log/LogBackgroundServiceSchedulerTest.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,9 @@ public void testUpdateWithIncreaseAndDecrease() {
201201
Assert.assertEquals(1250, scheduler.getScheduleDelay());
202202

203203
scheduler.update(1000);
204-
Assert.assertEquals(625, scheduler.getScheduleDelay());
205-
206-
scheduler.update(1000);
207-
Assert.assertEquals(313, scheduler.getScheduleDelay());
208-
209-
scheduler.update(1000);
210-
Assert.assertEquals(157, scheduler.getScheduleDelay());
211-
212-
scheduler.update(1000);
213-
Assert.assertEquals(100, scheduler.getScheduleDelay());
204+
Assert.assertEquals(1000, scheduler.getScheduleDelay());
214205

215206
scheduler.update(1000);
216-
Assert.assertEquals(100, scheduler.getScheduleDelay());
207+
Assert.assertEquals(1000, scheduler.getScheduleDelay());
217208
}
218209
}

0 commit comments

Comments
 (0)