geode-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (GEODE-651) Chunk classes need unit tests
Date Wed, 16 Dec 2015 00:18:46 GMT

    [ https://issues.apache.org/jira/browse/GEODE-651?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15059173#comment-15059173
] 

ASF GitHub Bot commented on GEODE-651:
--------------------------------------

Github user dschneider-pivotal commented on a diff in the pull request:

    https://github.com/apache/incubator-geode/pull/60#discussion_r47719953
  
    --- Diff: gemfire-core/src/test/java/com/gemstone/gemfire/internal/offheap/GemFireChunkJUnitTest.java
---
    @@ -0,0 +1,945 @@
    +/*
    + * 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 com.gemstone.gemfire.internal.offheap;
    +
    +import static org.assertj.core.api.Assertions.assertThat;
    +import static org.junit.Assert.assertArrayEquals;
    +import static org.junit.Assert.assertEquals;
    +import static org.junit.Assert.assertNotNull;
    +import static org.mockito.Mockito.atLeastOnce;
    +import static org.mockito.Mockito.doNothing;
    +import static org.mockito.Mockito.doReturn;
    +import static org.mockito.Mockito.mock;
    +import static org.mockito.Mockito.spy;
    +import static org.mockito.Mockito.times;
    +import static org.mockito.Mockito.verify;
    +import static org.mockito.Mockito.when;
    +
    +import java.io.IOException;
    +import java.nio.ByteBuffer;
    +
    +import org.junit.After;
    +import org.junit.Before;
    +import org.junit.Test;
    +import org.junit.experimental.categories.Category;
    +
    +import com.gemstone.gemfire.LogWriter;
    +import com.gemstone.gemfire.compression.Compressor;
    +import com.gemstone.gemfire.internal.DSCODE;
    +import com.gemstone.gemfire.internal.HeapDataOutputStream;
    +import com.gemstone.gemfire.internal.Version;
    +import com.gemstone.gemfire.internal.cache.BytesAndBitsForCompactor;
    +import com.gemstone.gemfire.internal.cache.CachePerfStats;
    +import com.gemstone.gemfire.internal.cache.EntryEventImpl;
    +import com.gemstone.gemfire.internal.cache.RegionEntryContext;
    +import com.gemstone.gemfire.internal.offheap.MemoryBlock.State;
    +import com.gemstone.gemfire.test.junit.categories.UnitTest;
    +
    +@Category(UnitTest.class)
    +public class GemFireChunkJUnitTest extends AbstractStoredObjectTestBase {
    +
    +  private MemoryAllocator ma;
    +
    +  static {
    +    ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true);
    +  }
    +
    +  @Before
    +  public void setUp() {
    +    OutOfOffHeapMemoryListener ooohml = mock(OutOfOffHeapMemoryListener.class);
    +    OffHeapMemoryStats stats = mock(OffHeapMemoryStats.class);
    +    LogWriter lw = mock(LogWriter.class);
    +
    +    ma = SimpleMemoryAllocatorImpl.create(ooohml, stats, lw, 3, OffHeapStorage.MIN_SLAB_SIZE
* 3, OffHeapStorage.MIN_SLAB_SIZE);
    +  }
    +
    +  @After
    +  public void tearDown() {
    +    SimpleMemoryAllocatorImpl.freeOffHeapMemory();
    +  }
    +
    +  @Override
    +  public Object getValue() {
    +    return Long.valueOf(Long.MAX_VALUE);
    +  }
    +
    +  @Override
    +  public byte[] getValueAsByteArray() {
    +    return convertValueToByteArray(getValue());
    +  }
    +
    +  private byte[] convertValueToByteArray(Object value) {
    +    return ByteBuffer.allocate(Long.SIZE / Byte.SIZE).putLong((Long) value).array();
    +  }
    +
    +  @Override
    +  public Object convertByteArrayToObject(byte[] valueInByteArray) {
    +    return ByteBuffer.wrap(valueInByteArray).getLong();
    +  }
    +
    +  @Override
    +  public Object convertSerializedByteArrayToObject(byte[] valueInSerializedByteArray)
{
    +    return EntryEventImpl.deserialize(valueInSerializedByteArray);
    +  }
    +
    +  @Override
    +  public GemFireChunk createValueAsUnserializedStoredObject(Object value) {
    +    byte[] valueInByteArray;
    +    if (value instanceof Long) {
    +      valueInByteArray = convertValueToByteArray(value);
    +    } else {
    +      valueInByteArray = (byte[]) value;
    +    }
    +
    +    boolean isSerialized = false;
    +    boolean isCompressed = false;
    +
    +    return createChunk(valueInByteArray, isSerialized, isCompressed);
    +  }
    +
    +  @Override
    +  public GemFireChunk createValueAsSerializedStoredObject(Object value) {
    +    byte[] valueInSerializedByteArray = EntryEventImpl.serialize(value);
    +
    +    boolean isSerialized = true;
    +    boolean isCompressed = false;
    +
    +    return createChunk(valueInSerializedByteArray, isSerialized, isCompressed);
    +  }
    +
    +  private GemFireChunk createChunk(byte[] v, boolean isSerialized, boolean isCompressed)
{
    +    GemFireChunk chunk = (GemFireChunk) ma.allocateAndInitialize(v, isSerialized, isCompressed,
GemFireChunk.TYPE);
    +    chunk.setSerializedValue(v);
    --- End diff --
    
    remove the calls to setSerializedValue, setSerialized, and setCompressed since allocateAndInitialize
call them


> Chunk classes need unit tests
> -----------------------------
>
>                 Key: GEODE-651
>                 URL: https://issues.apache.org/jira/browse/GEODE-651
>             Project: Geode
>          Issue Type: Sub-task
>          Components: offheap
>            Reporter: Sai Boorlagadda
>            Assignee: Sai Boorlagadda
>
> Chunk and its subclasses (GemFireChunk, ChunkWithHeapForm, and GemFireChunkSlice) need
unit tests.
> GemFireChunkFactory needs a unit test.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message