Skip to content

Commit

Permalink
Add coverage for MetadataStorageACtionHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
kfaraz committed Jun 27, 2024
1 parent 332a4d6 commit b2146c7
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.druid.metadata;

import com.google.common.base.Optional;
import org.apache.druid.error.DruidException;
import org.apache.druid.guice.annotations.ExtensionPoint;
import org.apache.druid.indexer.TaskIdentifier;
import org.apache.druid.indexer.TaskInfo;
Expand Down Expand Up @@ -166,22 +167,30 @@ default List<TaskInfo<EntryType, StatusType>> getTaskInfos(
* Task logs are not used anymore and this method is never called by Druid code.
* It has been retained only for backwards compatibility with older extensions.
* New extensions must not implement this method.
*
* @throws DruidException of category UNSUPPORTED whenever called.
*/
@Deprecated
default boolean addLog(String entryId, LogType log)
{
throw new UnsupportedOperationException("Task actions are not logged anymore.");
throw DruidException.defensive()
.ofCategory(DruidException.Category.UNSUPPORTED)
.build("Task actions are not logged anymore.");
}

/**
* Task logs are not used anymore and this method is never called by Druid code.
* It has been retained only for backwards compatibility with older extensions.
* New extensions must not implement this method.
*
* @throws DruidException of category UNSUPPORTED whenever called.
*/
@Deprecated
default List<LogType> getLogs(String entryId)
{
throw new UnsupportedOperationException("Task actions are not logged anymore.");
throw DruidException.defensive()
.ofCategory(DruidException.Category.UNSUPPORTED)
.build("Task actions are not logged anymore.");
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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 org.apache.druid.metadata;

import com.google.common.base.Optional;
import org.apache.druid.error.DruidException;
import org.apache.druid.indexer.TaskIdentifier;
import org.apache.druid.indexer.TaskInfo;
import org.joda.time.DateTime;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
* Tests the default methods of the interface {@link MetadataStorageActionHandler}.
* Required only for coverage as these methods are already being tested in
* {@code SQLMetadataStorageActionHandlerTest}.
*/
public class MetadataStorageActionHandlerTest
{

private MetadataStorageActionHandler<String, String, String, String> handler;

@Before
public void setup()
{
this.handler = new MetadataStorageActionHandler<String, String, String, String>()
{
@Override
public void insert(
String id,
DateTime timestamp,
String dataSource,
String entry,
boolean active,
@Nullable String status,
String type,
String groupId
)
{

}

@Override
public boolean setStatus(String entryId, boolean active, String status)
{
return false;
}

@Override
public Optional<String> getEntry(String entryId)
{
return null;
}

@Override
public Optional<String> getStatus(String entryId)
{
return null;
}

@Nullable
@Override
public TaskInfo<String, String> getTaskInfo(String entryId)
{
return null;
}

@Override
public List<TaskInfo<String, String>> getTaskInfos(
Map<TaskLookup.TaskLookupType, TaskLookup> taskLookups,
@Nullable String datasource
)
{
return Collections.emptyList();
}

@Override
public List<TaskInfo<TaskIdentifier, String>> getTaskStatusList(
Map<TaskLookup.TaskLookupType, TaskLookup> taskLookups,
@Nullable String datasource
)
{
return Collections.emptyList();
}

@Override
public boolean addLock(String entryId, String lock)
{
return false;
}

@Override
public boolean replaceLock(String entryId, long oldLockId, String newLock)
{
return false;
}

@Override
public void removeLock(long lockId)
{

}

@Override
public void removeTasksOlderThan(long timestamp)
{

}

@Override
public Map<Long, String> getLocks(String entryId)
{
return Collections.emptyMap();
}

@Override
public Long getLockId(String entryId, String lock)
{
return 0L;
}

@Override
public void populateTaskTypeAndGroupIdAsync()
{

}
};
}

@Test
public void testAddLogThrowsUnsupportedException()
{
Exception exception = Assert.assertThrows(
DruidException.class,
() -> handler.addLog("abcd", "logentry")

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
MetadataStorageActionHandler.addLog
should be avoided because it has been deprecated.
);
Assert.assertEquals(
"Task actions are not logged anymore.",
exception.getMessage()
);
}

@Test
public void testGetLogsThrowsUnsupportedException()
{
Exception exception = Assert.assertThrows(
DruidException.class,
() -> handler.getLogs("abcd")

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
MetadataStorageActionHandler.getLogs
should be avoided because it has been deprecated.
);
Assert.assertEquals(
"Task actions are not logged anymore.",
exception.getMessage()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void testDuplicateInsertThrowsEntryExistsException()
public void testAddLogThrowsUnsupportedException()
{
Exception exception = Assert.assertThrows(
UnsupportedOperationException.class,
DruidException.class,
() -> handler.addLog("abcd", ImmutableMap.of("logentry", "created"))
);
Assert.assertEquals(
Expand All @@ -261,7 +261,7 @@ public void testAddLogThrowsUnsupportedException()
public void testGetLogsThrowsUnsupportedException()
{
Exception exception = Assert.assertThrows(
UnsupportedOperationException.class,
DruidException.class,
() -> handler.getLogs("abcd")
);
Assert.assertEquals(
Expand Down

0 comments on commit b2146c7

Please sign in to comment.