Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some minor test issues raised by CodeQL. #17616

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,25 @@
package org.apache.druid.k8s.overlord;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Supplier;
import org.apache.druid.indexing.common.TestUtils;
import org.apache.druid.indexing.common.config.TaskConfig;
import org.apache.druid.indexing.common.config.TaskConfigBuilder;
import org.apache.druid.java.util.emitter.service.ServiceEmitter;
import org.apache.druid.k8s.overlord.common.DruidKubernetesClient;
import org.apache.druid.k8s.overlord.execution.KubernetesTaskRunnerDynamicConfig;
import org.apache.druid.k8s.overlord.taskadapter.TaskAdapter;
import org.apache.druid.server.DruidNode;
import org.apache.druid.server.log.StartupLoggingConfig;
import org.apache.druid.tasklogs.NoopTaskLogs;
import org.apache.druid.tasklogs.TaskLogs;
import org.easymock.Mock;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.Properties;

public class KubernetesTaskRunnerFactoryTest
{
private ObjectMapper objectMapper;
private KubernetesTaskRunnerConfig kubernetesTaskRunnerConfig;
private StartupLoggingConfig startupLoggingConfig;
private TaskLogs taskLogs;
private DruidNode druidNode;
private TaskConfig taskConfig;
private Properties properties;

private DruidKubernetesClient druidKubernetesClient;
@Mock private ServiceEmitter emitter;
@Mock private Supplier<KubernetesTaskRunnerDynamicConfig> dynamicConfigRef;
@Mock private TaskAdapter taskAdapter;

@Before
Expand All @@ -61,19 +48,7 @@ public void setup()
kubernetesTaskRunnerConfig = KubernetesTaskRunnerConfig.builder()
.withCapacity(1)
.build();
startupLoggingConfig = new StartupLoggingConfig();
taskLogs = new NoopTaskLogs();
druidNode = new DruidNode(
"test",
"",
false,
0,
1,
true,
false
);
taskConfig = new TaskConfigBuilder().setBaseDir("/tmp").build();
properties = new Properties();
druidKubernetesClient = new DruidKubernetesClient();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@ public List reverseFetchKeys(Object value)
}

@Override
@SuppressWarnings("EqualsHashCode")
public int hashCode()
{
return 0;
}

@Override
public boolean equals(Object obj)
{
return obj instanceof MockDataFetcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ public List reverseFetchKeys(Object value)
}

@Override
@SuppressWarnings("EqualsHashCode")
public int hashCode()
{
return 0;
}

@Override
public boolean equals(Object obj)
{
return obj instanceof MockDataFetcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ public List reverseFetchKeys(Object value)
}

@Override
@SuppressWarnings("EqualsHashCode")
public int hashCode()
{
return 0;
}

@Override
public boolean equals(Object obj)
{
return obj instanceof MockDataFetcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ public File fetchSegmentFile(
location.getBucketId()
);
if (!zippedFile.isPresent()) {
throw new ISE("Can't find segment file for location[%s] at path[%s]", location);
throw new ISE("Can't find segment file for location[%s] at path[%s]", location, zippedFile);
}
final File fetchedFile = new File(partitionDir, StringUtils.format("temp_%s", location.getSubTaskId()));
FileUtils.writeAtomically(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ public LookupExtractor get()
}

@Override
@SuppressWarnings("EqualsHashCode")
public int hashCode()
{
return 0;
}

@Override
public boolean equals(Object other)
{
return other instanceof TestLookupExtractorFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2567,37 +2567,15 @@

List<SearchHit> values = new ArrayList<>();
while (index < objects.length && !(objects[index] instanceof DateTime)) {
values.add(new SearchHit(dim, objects[index++].toString(), (Integer) objects[index++]));
values.add(new SearchHit(dim, objects[index].toString(), (Integer) objects[index + 1]));
Dismissed Show dismissed Hide dismissed
index += 2;
}

retVal.add(new Result<>(timestamp, new SearchResultValue(values)));
}
return retVal;
}

private Iterable<ResultRow> makeGroupByResults(GroupByQuery query, Object... objects)
{
List<ResultRow> retVal = new ArrayList<>();
int index = 0;
while (index < objects.length) {
final DateTime timestamp = (DateTime) objects[index++];
final Map<String, Object> rowMap = (Map<String, Object>) objects[index++];
final ResultRow row = ResultRow.create(query.getResultRowSizeWithoutPostAggregators());

if (query.getResultRowHasTimestamp()) {
row.set(0, timestamp.getMillis());
}

for (Map.Entry<String, Object> entry : rowMap.entrySet()) {
final int position = query.getResultRowSignature().indexOf(entry.getKey());
row.set(position, entry.getValue());
}

retVal.add(row);
}
return retVal;
}

private <T> T makeMock(List<Object> mocks, Class<T> clazz)
{
T obj = EasyMock.createMock(clazz);
Expand Down
Loading