Search in sources :

Example 1 with TDClientHttpNotFoundException

use of com.treasuredata.client.TDClientHttpNotFoundException in project fluency by komamitsu.

the class TreasureDataSenderTest method sendWithCreatingTable.

@Test
void sendWithCreatingTable() throws IOException {
    AtomicInteger importToTableCalls = new AtomicInteger();
    doAnswer(invocation -> {
        if (importToTableCalls.getAndIncrement() == 0) {
            throw new TDClientHttpNotFoundException("Not Found!!!!");
        }
        assertImportedFile(invocation.getArgument(2));
        return null;
    }).when(client).importFile(anyString(), anyString(), any(File.class), 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(0)).createDatabase(anyString());
    verify(client, times(1)).createTable(eq(DB), eq(TABLE));
    UUID.fromString(uniqueIdArgumentCaptor.getValue());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) File(java.io.File) TDClientHttpNotFoundException(com.treasuredata.client.TDClientHttpNotFoundException) Test(org.junit.jupiter.api.Test)

Example 2 with TDClientHttpNotFoundException

use of com.treasuredata.client.TDClientHttpNotFoundException in project fluency by komamitsu.

the class TreasureDataSenderTest method sendWithLackOfPermissionOnDatabase.

@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) {
        assertTrue(true);
    }
    ArgumentCaptor<String> uniqueIdArgumentCaptor = ArgumentCaptor.forClass(String.class);
    verify(client, times(1)).importFile(eq(DB), eq(TABLE), any(File.class), uniqueIdArgumentCaptor.capture());
    verify(client, times(4)).createDatabase(eq(DB));
    verify(client, times(4)).existsDatabase(eq(DB));
    verify(client, times(1)).createTable(eq(DB), eq(TABLE));
    UUID.fromString(uniqueIdArgumentCaptor.getValue());
}
Also used : NonRetryableException(org.komamitsu.fluency.NonRetryableException) TDClientHttpConflictException(com.treasuredata.client.TDClientHttpConflictException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) File(java.io.File) TDClientHttpNotFoundException(com.treasuredata.client.TDClientHttpNotFoundException) Test(org.junit.jupiter.api.Test)

Example 3 with TDClientHttpNotFoundException

use of com.treasuredata.client.TDClientHttpNotFoundException in project fluency by komamitsu.

the class TreasureDataSenderTest method sendWithCreatingDatabase.

@Test
void sendWithCreatingDatabase() throws IOException {
    AtomicInteger importToTableCalls = new AtomicInteger();
    doAnswer(invocation -> {
        if (importToTableCalls.getAndIncrement() == 0) {
            throw new TDClientHttpNotFoundException("Not Found!!!!");
        }
        assertImportedFile(invocation.getArgument(2));
        return null;
    }).when(client).importFile(anyString(), anyString(), any(File.class), anyString());
    AtomicInteger createTableCalls = new AtomicInteger();
    doAnswer(invocation -> {
        if (createTableCalls.getAndIncrement() == 0) {
            throw new TDClientHttpNotFoundException("Not Found!!!!");
        }
        return null;
    }).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());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) File(java.io.File) TDClientHttpNotFoundException(com.treasuredata.client.TDClientHttpNotFoundException) Test(org.junit.jupiter.api.Test)

Aggregations

TDClientHttpNotFoundException (com.treasuredata.client.TDClientHttpNotFoundException)3 File (java.io.File)3 Test (org.junit.jupiter.api.Test)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 TDClientHttpConflictException (com.treasuredata.client.TDClientHttpConflictException)1 NonRetryableException (org.komamitsu.fluency.NonRetryableException)1