Github user zsxwing commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5868#discussion_r30187721
  
    --- Diff: 
core/src/test/java/org/apache/spark/shuffle/unsafe/PackedRecordPointerSuite.java
 ---
    @@ -0,0 +1,93 @@
    +/*
    + * 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.spark.shuffle.unsafe;
    +
    +import org.junit.Test;
    +import static org.junit.Assert.*;
    +
    +import org.apache.spark.unsafe.memory.ExecutorMemoryManager;
    +import org.apache.spark.unsafe.memory.MemoryAllocator;
    +import org.apache.spark.unsafe.memory.MemoryBlock;
    +import org.apache.spark.unsafe.memory.TaskMemoryManager;
    +import static org.apache.spark.shuffle.unsafe.PackedRecordPointer.*;
    +
    +public class PackedRecordPointerSuite {
    +
    +  @Test
    +  public void heap() {
    +    final TaskMemoryManager memoryManager =
    +      new TaskMemoryManager(new 
ExecutorMemoryManager(MemoryAllocator.HEAP));
    +    final MemoryBlock page0 = memoryManager.allocatePage(100);
    +    final MemoryBlock page1 = memoryManager.allocatePage(100);
    +    final long addressInPage1 = 
memoryManager.encodePageNumberAndOffset(page1, 42);
    +    PackedRecordPointer packedPointer = new PackedRecordPointer();
    +    packedPointer.set(PackedRecordPointer.packPointer(addressInPage1, 
360));
    +    assertEquals(360, packedPointer.getPartitionId());
    +    assertEquals(addressInPage1, packedPointer.getRecordPointer());
    +    memoryManager.cleanUpAllAllocatedMemory();
    +  }
    +
    +  @Test
    +  public void offHeap() {
    +    final TaskMemoryManager memoryManager =
    +      new TaskMemoryManager(new 
ExecutorMemoryManager(MemoryAllocator.UNSAFE));
    +    final MemoryBlock page0 = memoryManager.allocatePage(100);
    +    final MemoryBlock page1 = memoryManager.allocatePage(100);
    +    final long addressInPage1 = 
memoryManager.encodePageNumberAndOffset(page1, 42);
    +    PackedRecordPointer packedPointer = new PackedRecordPointer();
    +    packedPointer.set(PackedRecordPointer.packPointer(addressInPage1, 
360));
    +    assertEquals(360, packedPointer.getPartitionId());
    +    assertEquals(addressInPage1, packedPointer.getRecordPointer());
    +    memoryManager.cleanUpAllAllocatedMemory();
    +  }
    +
    +  @Test
    +  public void maximumPartitionIdCanBeEncoded() {
    +    PackedRecordPointer packedPointer = new PackedRecordPointer();
    +    packedPointer.set(PackedRecordPointer.packPointer(0, 
MAXIMUM_PARTITION_ID));
    +    assertEquals(MAXIMUM_PARTITION_ID, packedPointer.getPartitionId());
    +  }
    +
    +  @Test
    +  public void 
partitionIdsGreaterThanMaximumPartitionIdWillOverflowOrTriggerError() {
    +    PackedRecordPointer packedPointer = new PackedRecordPointer();
    +    try {
    +      // Pointers greater than the maximum partition ID will overflow or 
trigger an assertion error
    +      packedPointer.set(PackedRecordPointer.packPointer(0, 
MAXIMUM_PARTITION_ID + 1));
    +      assertFalse(MAXIMUM_PARTITION_ID  + 1 == 
packedPointer.getPartitionId());
    +    } catch (AssertionError e ) {
    --- End diff --
    
    Since you use `assertFalse` here, it won't throw  `AssertionError`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to