content: /*
   * Copyright 2021-2024 Aklivity Inc.
   *
   * Aklivity 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 io.aklivity.zilla.runtime.engine.internal.layouts;
  
  import static org.hamcrest.MatcherAssert.assertThat;
  import static org.hamcrest.Matchers.equalTo;
  
  import java.nio.file.Path;
  import java.nio.file.Paths;
  
  import org.agrona.DirectBuffer;
  import org.agrona.concurrent.UnsafeBuffer;
  import org.junit.Test;
  
  public class EventsLayoutTest
  {
      private static final Path PATH = Paths.get("target/zilla-itests/events0");
      private static final int CAPACITY = 1024;
  
      private int msgTypeId;
  
      @Test
      public void shouldWriteAndReadEvents()
      {
          // GIVEN
          EventsLayout layout = new EventsLayout.Builder()
              .path(PATH)
              .capacity(CAPACITY)
              .build();
          layout.writeEvent(42, new UnsafeBuffer(), 0, 0);
          msgTypeId = 0;
          EventsLayout.EventAccessor accessor = layout.createEventAccessor();
  
          // WHEN
          int count = accessor.readEvent(this::readEvent, 1);
  
          // THEN
          assertThat(count, equalTo(1));
          assertThat(msgTypeId, equalTo(42));
      }
  
      private void readEvent(
          int msgTypeId,
          DirectBuffer buffer,
          int index,
          int length)
      {
          this.msgTypeId = msgTypeId;
      }
  }
  