djkevincr commented on a change in pull request #118: MNEMONIC-515: PMDK based Persistent Memory Service URL: https://github.com/apache/mnemonic/pull/118#discussion_r317892780
########## File path: mnemonic-core/src/test/java/org/apache/mnemonic/PMDKNonVolatileMemAllocatorNGTest.java ########## @@ -0,0 +1,132 @@ +/* + * 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.mnemonic; + +import java.nio.ByteBuffer; +import java.util.Random; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * + */ + +public class PMDKNonVolatileMemAllocatorNGTest { + @Test + public void testPMemByteBuffer() { + Random randomGenerator = new Random(); + NonVolatileMemAllocator act = new NonVolatileMemAllocator(Utils.getNonVolatileMemoryAllocatorService("pmdk_pmem"), + 1024 * 1024 * 1024, "./pmdk_pmtest.dat", true); + act.setBufferReclaimer(new Reclaim<ByteBuffer>() { + @Override + public boolean reclaim(ByteBuffer mres, Long sz) { + System.out.println(String.format("Reclaim Memory Buffer: %X Size: %s", System.identityHashCode(mres), + null == sz ? "NULL" : sz.toString())); + return false; + } + }); + MemBufferHolder<?> mbh; + for (int idx = 1; idx <= 500; ++idx) { + int size = randomGenerator.nextInt(1024 * 1024) + 1024 * 1024; + mbh = act.createBuffer(size); + Assert.assertNotNull(mbh); + for (int i = 0; i < size; i++) { + mbh.get().put((byte) randomGenerator.nextInt(255)); + } + // if (bb.hasArray()) randomGenerator.nextBytes(bb.array()); + Assert.assertEquals(size, mbh.get().capacity()); + System.out.println(String.format("[Seq.%d] size %d - %d, (%s)", idx, size, mbh.get().capacity(), Review comment: Rather using System.out.println() print the reason etc why JUnit test case failed. You can pass the same content as parameter to assertEquals() method so that, if test case is failed, it will print reason why it was failed. ``` public static void assertEquals(String message, long expected, long actual) { assertEquals(message, (Object)expected, (Object)actual); } ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
