Skip to content

Commit

Permalink
GEODE-6674: only create StringBuilder if needed (apache#3511)
Browse files Browse the repository at this point in the history
* added unit tests for Put65 when region or key are null

* no longer allocates a StringBuilder for every client put message
  • Loading branch information
dschneider-pivotal authored Apr 30, 2019
1 parent 59c76ee commit 52abb90
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public void cmdExecute(final Message clientMessage, final ServerConnection serve
final SecurityService securityService, long p_start)
throws IOException, InterruptedException {
long start = p_start;
final StringBuilder errMessage = new StringBuilder();
final CacheServerStats stats = serverConnection.getCacheServerStats();

// requiresResponse = true;
Expand Down Expand Up @@ -159,6 +158,7 @@ public void cmdExecute(final Message clientMessage, final ServerConnection serve

// Process the put request
if (key == null || regionName == null) {
final StringBuilder errMessage = new StringBuilder();
if (key == null) {
final String putMsg = " The input key for the put request is null";
if (isDebugEnabled) {
Expand Down Expand Up @@ -193,8 +193,7 @@ public void cmdExecute(final Message clientMessage, final ServerConnection serve
if (isDebugEnabled) {
logger.debug("{}:{}", serverConnection.getName(), putMsg);
}
errMessage.append(putMsg);
writeErrorResponse(clientMessage, MessageType.PUT_DATA_ERROR, errMessage.toString(),
writeErrorResponse(clientMessage, MessageType.PUT_DATA_ERROR, putMsg,
serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,32 @@ public void noSecurityShouldSucceed() throws Exception {
verify(this.replyMessage).send(this.serverConnection);
}

@Test
public void noRegionNameShouldFail() throws Exception {
when(this.securityService.isClientSecurityRequired()).thenReturn(false);
when(this.regionNamePart.getString()).thenReturn(null);

this.put65.cmdExecute(this.message, this.serverConnection, this.securityService, 0);

ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
verify(this.errorResponseMessage).addStringPart(argument.capture());
assertThat(argument.getValue()).contains("The input region name for the put request is null");
verify(this.errorResponseMessage).send(this.serverConnection);
}

@Test
public void noKeyShouldFail() throws Exception {
when(this.securityService.isClientSecurityRequired()).thenReturn(false);
when(this.keyPart.getStringOrObject()).thenReturn(null);

this.put65.cmdExecute(this.message, this.serverConnection, this.securityService, 0);

ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
verify(this.errorResponseMessage).addStringPart(argument.capture());
assertThat(argument.getValue()).contains("The input key for the put request is null");
verify(this.errorResponseMessage).send(this.serverConnection);
}

@Test
public void integratedSecurityShouldSucceedIfAuthorized() throws Exception {
when(this.securityService.isClientSecurityRequired()).thenReturn(true);
Expand Down

0 comments on commit 52abb90

Please sign in to comment.