github.com/lirm/aeron-go@v0.0.0-20230415210743-920325491dc4/aeron/util/memmap/memmap_test.go (about)

     1  // Copyright 2016 Stanislav Liberman
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  // http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package memmap
    16  
    17  import (
    18  	"fmt"
    19  	"testing"
    20  
    21  	"github.com/lirm/aeron-go/aeron/atomic"
    22  )
    23  
    24  const (
    25  	MMAP = "mmap.bin"
    26  )
    27  
    28  func TestMmapBasics(t *testing.T) {
    29  	t.Log("Beginning test")
    30  	mmap, err := NewFile(MMAP, 0, 8000)
    31  	defer mmap.Close()
    32  	// t.Logf("mmap: %v, len:%d, err:%v", mmap.GetMemoryPtr(), mmap.GetMemorySize(), err)
    33  	fmt.Printf("mmap: %v, len:%d, err:%v\n", mmap.GetMemoryPtr(), mmap.GetMemorySize(), err)
    34  
    35  	buf := atomic.MakeBuffer(mmap.GetMemoryPtr(), mmap.GetMemorySize())
    36  	// t.Logf("created atomic buffer: %v", buf)
    37  	fmt.Printf("created atomic buffer: %v\n", buf)
    38  
    39  	//    buf.Fill(0)
    40  
    41  	num := buf.GetInt64Volatile(0)
    42  	// t.Logf("1: Got %d stuff from file", num)
    43  	fmt.Printf("1: Got %d stuff from file\n", num)
    44  
    45  	var expected int64 = 42
    46  	buf.PutInt64Ordered(0, expected)
    47  	num = buf.GetInt64Volatile(0)
    48  	t.Logf("2: Got %d stuff from file\n", num)
    49  	if num != expected {
    50  		t.Fail()
    51  	}
    52  }