// Path: fluency-core/src/test/java/org/komamitsu/fluency/JsonRecordFormatter.java
// public class JsonRecordFormatter
//         extends AbstractRecordFormatter
// {
//     private ObjectMapper objectMapper = new ObjectMapper();
// 
//     public JsonRecordFormatter()
//     {
//         super(new Config());
//     }
// 
//     @Override
//     public byte[] format(String tag, Object timestamp, Map<String, Object> data)
//     {
//         try {
//             return objectMapper.writeValueAsBytes(data);
//         }
//         catch (JsonProcessingException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     @Override
//     public byte[] formatFromMessagePack(String tag, Object timestamp, byte[] mapValue, int offset, int len)
//     {
//         throw new RuntimeException("Shouldn't be called");
//     }
// 
//     @Override
//     public byte[] formatFromMessagePack(String tag, Object timestamp, ByteBuffer mapValue)
//     {
//         throw new RuntimeException("Shouldn't be called");
//     }
// 
//     @Override
//     public String formatName()
//     {
//         return "json";
//     }
// }
// 
// Path: fluency-core/src/main/java/org/komamitsu/fluency/ingester/Ingester.java
// public interface Ingester
//         extends Closeable
// {
//     void ingest(String tag, ByteBuffer dataBuffer)
//             throws IOException;
// 
//     Sender getSender();
// }
// 
// Path: fluency-core/src/main/java/org/komamitsu/fluency/recordformat/RecordFormatter.java
// public interface RecordFormatter
// {
//     byte[] format(String tag, Object timestamp, Map<String, Object> data);
// 
//     byte[] formatFromMessagePack(String tag, Object timestamp, byte[] mapValue, int offset, int len);
// 
//     byte[] formatFromMessagePack(String tag, Object timestamp, ByteBuffer mapValue);
// 
//     String formatName();
// 
//     class Config
//     {
//         private List<Module> jacksonModules = Collections.emptyList();
// 
//         public List<Module> getJacksonModules()
//         {
//             return jacksonModules;
//         }
// 
//         public void setJacksonModules(List<Module> jacksonModules)
//         {
//             this.jacksonModules = jacksonModules;
//         }
//     }
// }
// 
// Path: fluency-core/src/main/java/org/komamitsu/fluency/util/Tuple.java
// public class Tuple<F, S>
// {
//     private final F first;
//     private final S second;
// 
//     public Tuple(F first, S second)
//     {
//         this.first = first;
//         this.second = second;
//     }
// 
//     public F getFirst()
//     {
//         return first;
//     }
// 
//     public S getSecond()
//     {
//         return second;
//     }
// }


import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.komamitsu.fluency.JsonRecordFormatter;
import org.komamitsu.fluency.ingester.Ingester;
import org.komamitsu.fluency.recordformat.RecordFormatter;
import org.komamitsu.fluency.util.Tuple;
import org.mockito.ArgumentCaptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.number.OrderingComparison.greaterThan;
import static org.hamcrest.number.OrderingComparison.lessThan;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
        verify(ingester, times(0)).ingest(anyString(), any(ByteBuffer.class));

        buffer.flush(ingester, true);

        verify(ingester, times(1)).ingest(eq("foodb.bartbl"), any(ByteBuffer.class));
    }

    @Test
    void testFileBackup()
            throws IOException
    {
        bufferConfig.setFileBackupDir(System.getProperty("java.io.tmpdir"));
        bufferConfig.setFileBackupPrefix("FileBackupTest");

        // Just for cleaning backup files
        try (Buffer buffer = new Buffer(bufferConfig, recordFormatter)) {
            buffer.clearBackupFiles();
        }
        try (Buffer buffer = new Buffer(bufferConfig, recordFormatter)) {
            assertEquals(0, buffer.getBufferedDataSize());
        }

        long currentTime = System.currentTimeMillis() / 1000;
        Map<String, Object> event0 = ImmutableMap.of("name", "a", "age", 42);
        Map<String, Object> event1 = ImmutableMap.of("name", "b", "age", 99);
        try (Buffer buffer = new Buffer(bufferConfig, recordFormatter)) {
            buffer.append("foo", currentTime, event0);
            buffer.append("bar", currentTime, event1);
        }

// Path: fluency-core/src/test/java/org/komamitsu/fluency/JsonRecordFormatter.java
// public class JsonRecordFormatter
//         extends AbstractRecordFormatter
// {
//     private ObjectMapper objectMapper = new ObjectMapper();
// 
//     public JsonRecordFormatter()
//     {
//         super(new Config());
//     }
// 
//     @Override
//     public byte[] format(String tag, Object timestamp, Map<String, Object> data)
//     {
//         try {
//             return objectMapper.writeValueAsBytes(data);
//         }
//         catch (JsonProcessingException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     @Override
//     public byte[] formatFromMessagePack(String tag, Object timestamp, byte[] mapValue, int offset, int len)
//     {
//         throw new RuntimeException("Shouldn't be called");
//     }
// 
//     @Override
//     public byte[] formatFromMessagePack(String tag, Object timestamp, ByteBuffer mapValue)
//     {
//         throw new RuntimeException("Shouldn't be called");
//     }
// 
//     @Override
//     public String formatName()
//     {
//         return "json";
//     }
// }
// 
// Path: fluency-core/src/main/java/org/komamitsu/fluency/ingester/Ingester.java
// public interface Ingester
//         extends Closeable
// {
//     void ingest(String tag, ByteBuffer dataBuffer)
//             throws IOException;
// 
//     Sender getSender();
// }
// 
// Path: fluency-core/src/main/java/org/komamitsu/fluency/recordformat/RecordFormatter.java
// public interface RecordFormatter
// {
//     byte[] format(String tag, Object timestamp, Map<String, Object> data);
// 
//     byte[] formatFromMessagePack(String tag, Object timestamp, byte[] mapValue, int offset, int len);
// 
//     byte[] formatFromMessagePack(String tag, Object timestamp, ByteBuffer mapValue);
// 
//     String formatName();
// 
//     class Config
//     {
//         private List<Module> jacksonModules = Collections.emptyList();
// 
//         public List<Module> getJacksonModules()
//         {
//             return jacksonModules;
//         }
// 
//         public void setJacksonModules(List<Module> jacksonModules)
//         {
//             this.jacksonModules = jacksonModules;
//         }
//     }
// }
// 
// Path: fluency-core/src/main/java/org/komamitsu/fluency/util/Tuple.java
// public class Tuple<F, S>
// {
//     private final F first;
//     private final S second;
// 
//     public Tuple(F first, S second)
//     {
//         this.first = first;
//         this.second = second;
//     }
// 
//     public F getFirst()
//     {
//         return first;
//     }
// 
//     public S getSecond()
//     {
//         return second;
//     }
// }


// Path: fluency-core/src/test/java/org/komamitsu/fluency/buffer/BufferTest.java
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.komamitsu.fluency.JsonRecordFormatter;
import org.komamitsu.fluency.ingester.Ingester;
import org.komamitsu.fluency.recordformat.RecordFormatter;
import org.komamitsu.fluency.util.Tuple;
import org.mockito.ArgumentCaptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.number.OrderingComparison.greaterThan;
import static org.hamcrest.number.OrderingComparison.lessThan;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

        verify(ingester, times(0)).ingest(anyString(), any(ByteBuffer.class));

        buffer.flush(ingester, true);

        verify(ingester, times(1)).ingest(eq("foodb.bartbl"), any(ByteBuffer.class));
    }

    @Test
    void testFileBackup()
            throws IOException
    {
        bufferConfig.setFileBackupDir(System.getProperty("java.io.tmpdir"));
        bufferConfig.setFileBackupPrefix("FileBackupTest");

        // Just for cleaning backup files
        try (Buffer buffer = new Buffer(bufferConfig, recordFormatter)) {
            buffer.clearBackupFiles();
        }
        try (Buffer buffer = new Buffer(bufferConfig, recordFormatter)) {
            assertEquals(0, buffer.getBufferedDataSize());
        }

        long currentTime = System.currentTimeMillis() / 1000;
        Map<String, Object> event0 = ImmutableMap.of("name", "a", "age", 42);
        Map<String, Object> event1 = ImmutableMap.of("name", "b", "age", 99);
        try (Buffer buffer = new Buffer(bufferConfig, recordFormatter)) {
            buffer.append("foo", currentTime, event0);
            buffer.append("bar", currentTime, event1);
        }

        Ingester ingester = mock(Ingester.class);