// Path: src/main/java/com/yahoo/memory4/ResourceHandler.java
// enum ResourceType { MEMORY_MAPPED_FILE, NATIVE_MEMORY }


import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
import com.yahoo.memory4.ResourceHandler.ResourceType;
/*
 * Copyright 2017, Yahoo! Inc. Licensed under the terms of the
 * Apache License 2.0. See LICENSE file at the project root for terms.
 */

package com.yahoo.memory4;




public class AllocateDirectTest {

  @Test
  public void checkAllocateDirect() {
    int longs = 32;
    int bytes = longs << 3;
    WritableResourceHandler wh = WritableMemory.allocateDirect(bytes);
    WritableMemory wMem1 = wh.get();
    for (int i = 0; i<longs; i++) {
      wMem1.putLong(i << 3, i);
      assertEquals(wMem1.getLong(i << 3), i);
    }
    wMem1.toHexString("Test", 0, 32 * 8);
    wh.load();
    assertFalse(wh.isLoaded());
    wh.force();
// Path: src/main/java/com/yahoo/memory4/ResourceHandler.java
// enum ResourceType { MEMORY_MAPPED_FILE, NATIVE_MEMORY }


// Path: src/test/java/com/yahoo/memory4/AllocateDirectTest.java
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
import com.yahoo.memory4.ResourceHandler.ResourceType;

/*
 * Copyright 2017, Yahoo! Inc. Licensed under the terms of the
 * Apache License 2.0. See LICENSE file at the project root for terms.
 */

package com.yahoo.memory4;




public class AllocateDirectTest {

  @Test
  public void checkAllocateDirect() {
    int longs = 32;
    int bytes = longs << 3;
    WritableResourceHandler wh = WritableMemory.allocateDirect(bytes);
    WritableMemory wMem1 = wh.get();
    for (int i = 0; i<longs; i++) {
      wMem1.putLong(i << 3, i);
      assertEquals(wMem1.getLong(i << 3), i);
    }
    wMem1.toHexString("Test", 0, 32 * 8);
    wh.load();
    assertFalse(wh.isLoaded());
    wh.force();
    assertEquals(wh.getResourceType(), ResourceType.NATIVE_MEMORY);