Search in sources :

Example 6 with CloudBlobHolder

use of org.apache.druid.storage.azure.blob.CloudBlobHolder in project druid by druid-io.

the class AzureTaskLogsTest method test_killAll_noException_deletesAllTaskLogs.

@Test
public void test_killAll_noException_deletesAllTaskLogs() throws Exception {
    EasyMock.expect(inputDataConfig.getMaxListingLength()).andReturn(MAX_KEYS);
    EasyMock.expect(accountConfig.getMaxTries()).andReturn(MAX_TRIES).atLeastOnce();
    EasyMock.expect(timeSupplier.getAsLong()).andReturn(TIME_NOW);
    CloudBlobHolder object1 = AzureTestUtils.newCloudBlobHolder(CONTAINER, KEY_1, TIME_0);
    CloudBlobHolder object2 = AzureTestUtils.newCloudBlobHolder(CONTAINER, KEY_2, TIME_1);
    AzureCloudBlobIterable azureCloudBlobIterable = AzureTestUtils.expectListObjects(azureCloudBlobIterableFactory, MAX_KEYS, PREFIX_URI, ImmutableList.of(object1, object2));
    EasyMock.replay(object1, object2);
    AzureTestUtils.expectDeleteObjects(azureStorage, ImmutableList.of(object1, object2), ImmutableMap.of());
    EasyMock.replay(inputDataConfig, accountConfig, timeSupplier, azureCloudBlobIterable, azureCloudBlobIterableFactory, azureStorage);
    azureTaskLogs.killAll();
    EasyMock.verify(inputDataConfig, accountConfig, timeSupplier, object1, object2, azureCloudBlobIterable, azureCloudBlobIterableFactory, azureStorage);
}
Also used : CloudBlobHolder(org.apache.druid.storage.azure.blob.CloudBlobHolder) Test(org.junit.Test)

Example 7 with CloudBlobHolder

use of org.apache.druid.storage.azure.blob.CloudBlobHolder in project druid by druid-io.

the class AzureTestUtils method expectDeleteObjects.

public static void expectDeleteObjects(AzureStorage storage, List<CloudBlobHolder> deleteRequestsExpected, Map<CloudBlobHolder, Exception> deleteRequestToException) throws Exception {
    Map<CloudBlobHolder, IExpectationSetters<CloudBlobHolder>> requestToResultExpectationSetter = new HashMap<>();
    for (Map.Entry<CloudBlobHolder, Exception> requestsAndErrors : deleteRequestToException.entrySet()) {
        CloudBlobHolder deleteObject = requestsAndErrors.getKey();
        Exception exception = requestsAndErrors.getValue();
        IExpectationSetters<CloudBlobHolder> resultExpectationSetter = requestToResultExpectationSetter.get(deleteObject);
        if (resultExpectationSetter == null) {
            storage.emptyCloudBlobDirectory(deleteObject.getContainerName(), deleteObject.getName());
            resultExpectationSetter = EasyMock.<CloudBlobHolder>expectLastCall().andThrow(exception);
            requestToResultExpectationSetter.put(deleteObject, resultExpectationSetter);
        } else {
            resultExpectationSetter.andThrow(exception);
        }
    }
    for (CloudBlobHolder deleteObject : deleteRequestsExpected) {
        IExpectationSetters<CloudBlobHolder> resultExpectationSetter = requestToResultExpectationSetter.get(deleteObject);
        if (resultExpectationSetter == null) {
            storage.emptyCloudBlobDirectory(deleteObject.getContainerName(), deleteObject.getName());
            resultExpectationSetter = EasyMock.expectLastCall();
            requestToResultExpectationSetter.put(deleteObject, resultExpectationSetter);
        }
        resultExpectationSetter.andReturn(null);
    }
}
Also used : IExpectationSetters(org.easymock.IExpectationSetters) HashMap(java.util.HashMap) CloudBlobHolder(org.apache.druid.storage.azure.blob.CloudBlobHolder) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException)

Example 8 with CloudBlobHolder

use of org.apache.druid.storage.azure.blob.CloudBlobHolder in project druid by druid-io.

the class AzureTestUtils method newCloudBlobHolder.

public static CloudBlobHolder newCloudBlobHolder(String container, String prefix, long lastModifiedTimestamp) throws Exception {
    CloudBlobHolder object = EasyMock.createMock(CloudBlobHolder.class);
    EasyMock.expect(object.getContainerName()).andReturn(container).anyTimes();
    EasyMock.expect(object.getName()).andReturn(prefix).anyTimes();
    EasyMock.expect(object.getLastModifed()).andReturn(new Date(lastModifiedTimestamp)).anyTimes();
    return object;
}
Also used : CloudBlobHolder(org.apache.druid.storage.azure.blob.CloudBlobHolder) Date(java.util.Date)

Example 9 with CloudBlobHolder

use of org.apache.druid.storage.azure.blob.CloudBlobHolder in project druid by druid-io.

the class AzureTaskLogsTest method test_killOlderThan_nonrecoverableExceptionWhenListingObjects_doesntDeleteAnyTaskLogs.

@Test
public void test_killOlderThan_nonrecoverableExceptionWhenListingObjects_doesntDeleteAnyTaskLogs() throws Exception {
    boolean ioExceptionThrown = false;
    CloudBlobHolder object1 = null;
    AzureCloudBlobIterable azureCloudBlobIterable = null;
    try {
        EasyMock.expect(inputDataConfig.getMaxListingLength()).andReturn(MAX_KEYS);
        EasyMock.expect(accountConfig.getMaxTries()).andReturn(MAX_TRIES).atLeastOnce();
        object1 = AzureTestUtils.newCloudBlobHolder(CONTAINER, KEY_1, TIME_0);
        azureCloudBlobIterable = AzureTestUtils.expectListObjects(azureCloudBlobIterableFactory, MAX_KEYS, PREFIX_URI, ImmutableList.of(object1));
        EasyMock.replay(object1);
        AzureTestUtils.expectDeleteObjects(azureStorage, ImmutableList.of(), ImmutableMap.of(object1, NON_RECOVERABLE_EXCEPTION));
        EasyMock.replay(inputDataConfig, accountConfig, timeSupplier, azureCloudBlobIterable, azureCloudBlobIterableFactory, azureStorage);
        azureTaskLogs.killOlderThan(TIME_NOW);
    } catch (IOException e) {
        ioExceptionThrown = true;
    }
    Assert.assertTrue(ioExceptionThrown);
    EasyMock.verify(inputDataConfig, accountConfig, timeSupplier, object1, azureCloudBlobIterable, azureCloudBlobIterableFactory, azureStorage);
}
Also used : IOException(java.io.IOException) CloudBlobHolder(org.apache.druid.storage.azure.blob.CloudBlobHolder) Test(org.junit.Test)

Example 10 with CloudBlobHolder

use of org.apache.druid.storage.azure.blob.CloudBlobHolder in project druid by druid-io.

the class AzureTaskLogsTest method test_killOlderThan_noException_deletesOnlyTaskLogsOlderThan.

@Test
public void test_killOlderThan_noException_deletesOnlyTaskLogsOlderThan() throws Exception {
    EasyMock.expect(inputDataConfig.getMaxListingLength()).andReturn(MAX_KEYS);
    EasyMock.expect(accountConfig.getMaxTries()).andReturn(MAX_TRIES).atLeastOnce();
    CloudBlobHolder object1 = AzureTestUtils.newCloudBlobHolder(CONTAINER, KEY_1, TIME_0);
    CloudBlobHolder object2 = AzureTestUtils.newCloudBlobHolder(CONTAINER, KEY_2, TIME_FUTURE);
    AzureCloudBlobIterable azureCloudBlobIterable = AzureTestUtils.expectListObjects(azureCloudBlobIterableFactory, MAX_KEYS, PREFIX_URI, ImmutableList.of(object1, object2));
    EasyMock.replay(object1, object2);
    AzureTestUtils.expectDeleteObjects(azureStorage, ImmutableList.of(object1), ImmutableMap.of());
    EasyMock.replay(inputDataConfig, accountConfig, timeSupplier, azureCloudBlobIterable, azureCloudBlobIterableFactory, azureStorage);
    azureTaskLogs.killOlderThan(TIME_NOW);
    EasyMock.verify(inputDataConfig, accountConfig, timeSupplier, object1, object2, azureCloudBlobIterable, azureCloudBlobIterableFactory, azureStorage);
}
Also used : CloudBlobHolder(org.apache.druid.storage.azure.blob.CloudBlobHolder) Test(org.junit.Test)

Aggregations

CloudBlobHolder (org.apache.druid.storage.azure.blob.CloudBlobHolder)15 Test (org.junit.Test)11 IOException (java.io.IOException)4 CloudObjectLocation (org.apache.druid.data.input.impl.CloudObjectLocation)2 ImmutableList (com.google.common.collect.ImmutableList)1 ListBlobItem (com.microsoft.azure.storage.blob.ListBlobItem)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 InputSplit (org.apache.druid.data.input.InputSplit)1 MaxSizeSplitHintSpec (org.apache.druid.data.input.MaxSizeSplitHintSpec)1 ListBlobItemHolder (org.apache.druid.storage.azure.blob.ListBlobItemHolder)1 IExpectationSetters (org.easymock.IExpectationSetters)1