// Path: fluency-core/src/main/java/org/komamitsu/fluency/NonRetryableException.java
// public class NonRetryableException
//         extends RuntimeException
// {
//     public NonRetryableException(String message)
//     {
//         super(message);
//     }
// 
//     public NonRetryableException(String message, Throwable cause)
//     {
//         super(message, cause);
//     }
// }


import com.treasuredata.client.TDClient;
import com.treasuredata.client.TDClientHttpConflictException;
import com.treasuredata.client.TDClientHttpNotFoundException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.komamitsu.fluency.NonRetryableException;
import org.mockito.ArgumentCaptor;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.GZIPInputStream;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
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.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
        }).when(client).createTable(anyString(), anyString());

        sender.send(DB_AND_TABLE, ByteBuffer.wrap(DATA));
        ArgumentCaptor<String> uniqueIdArgumentCaptor = ArgumentCaptor.forClass(String.class);
        verify(client, times(2)).importFile(
                eq(DB), eq(TABLE), any(File.class), uniqueIdArgumentCaptor.capture());
        verify(client, times(1)).createDatabase(eq(DB));
        verify(client, times(2)).createTable(eq(DB), eq(TABLE));
        UUID.fromString(uniqueIdArgumentCaptor.getValue());
    }

    @Test
    public void sendWithLackOfPermissionOnDatabase()
            throws IOException
    {
        doThrow(new TDClientHttpNotFoundException("Not Found!!!!"))
                .when(client).importFile(anyString(), anyString(), any(File.class), anyString());

        doThrow(new TDClientHttpNotFoundException("Not Found!!!!"))
                .when(client).createTable(anyString(), anyString());

        doThrow(new TDClientHttpConflictException("Conflict!!!!"))
                .when(client).createDatabase(anyString());

        doReturn(false).when(client).existsDatabase(anyString());

        try {
            sender.send(DB_AND_TABLE, ByteBuffer.wrap(DATA));
            fail();
        }
// Path: fluency-core/src/main/java/org/komamitsu/fluency/NonRetryableException.java
// public class NonRetryableException
//         extends RuntimeException
// {
//     public NonRetryableException(String message)
//     {
//         super(message);
//     }
// 
//     public NonRetryableException(String message, Throwable cause)
//     {
//         super(message, cause);
//     }
// }


// Path: fluency-treasuredata/src/test/java/org/komamitsu/fluency/treasuredata/ingester/sender/TreasureDataSenderTest.java
import com.treasuredata.client.TDClient;
import com.treasuredata.client.TDClientHttpConflictException;
import com.treasuredata.client.TDClientHttpNotFoundException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.komamitsu.fluency.NonRetryableException;
import org.mockito.ArgumentCaptor;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.GZIPInputStream;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
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.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

        }).when(client).createTable(anyString(), anyString());

        sender.send(DB_AND_TABLE, ByteBuffer.wrap(DATA));
        ArgumentCaptor<String> uniqueIdArgumentCaptor = ArgumentCaptor.forClass(String.class);
        verify(client, times(2)).importFile(
                eq(DB), eq(TABLE), any(File.class), uniqueIdArgumentCaptor.capture());
        verify(client, times(1)).createDatabase(eq(DB));
        verify(client, times(2)).createTable(eq(DB), eq(TABLE));
        UUID.fromString(uniqueIdArgumentCaptor.getValue());
    }

    @Test
    public void sendWithLackOfPermissionOnDatabase()
            throws IOException
    {
        doThrow(new TDClientHttpNotFoundException("Not Found!!!!"))
                .when(client).importFile(anyString(), anyString(), any(File.class), anyString());

        doThrow(new TDClientHttpNotFoundException("Not Found!!!!"))
                .when(client).createTable(anyString(), anyString());

        doThrow(new TDClientHttpConflictException("Conflict!!!!"))
                .when(client).createDatabase(anyString());

        doReturn(false).when(client).existsDatabase(anyString());

        try {
            sender.send(DB_AND_TABLE, ByteBuffer.wrap(DATA));
            fail();
        }
        catch (NonRetryableException e) {