Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce memory allocations of calls to ByteBufer.duplicate() made in o…
…rg.apache.cassandra.transport.CBUtil#writeValue patch by Natnael Adere; reviewed by Benedict Elliott Smith, David Capwell for CASSANDRA-18212
- Loading branch information
Showing
4 changed files
with
134 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/unit/org/apache/cassandra/transport/WriteBytesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.cassandra.transport; | ||
|
||
import org.junit.Test; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.buffer.Unpooled; | ||
import org.apache.cassandra.io.util.FileUtils; | ||
import org.apache.cassandra.utils.Generators; | ||
import org.assertj.core.api.Assertions; | ||
|
||
import static org.quicktheories.QuickTheory.qt; | ||
|
||
|
||
public class WriteBytesTest | ||
{ | ||
@Test | ||
public void test() | ||
{ | ||
int maxBytes = 10_000; | ||
ByteBuf buf = Unpooled.buffer(maxBytes); | ||
qt().forAll(Generators.bytesAnyType(0, maxBytes)).checkAssert(bb -> { | ||
buf.clear(); | ||
|
||
int size = bb.remaining(); | ||
int pos = bb.position(); | ||
|
||
CBUtil.addBytes(bb, buf); | ||
|
||
// test for consumption | ||
Assertions.assertThat(bb.remaining()).isEqualTo(size); | ||
Assertions.assertThat(bb.position()).isEqualTo(pos); | ||
|
||
Assertions.assertThat(buf.writerIndex()).isEqualTo(size); | ||
for (int i = 0; i < size; i++) | ||
Assertions.assertThat(buf.getByte(buf.readerIndex() + i)).describedAs("byte mismatch at index %d", i).isEqualTo(bb.get(bb.position() + i)); | ||
FileUtils.clean(bb); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters