mirror of https://github.com/apache/druid.git
fix npe thrown from getEntry() and getStatus() SQLMetadataStorageActionHandler due to a non-exist entryId
This commit is contained in:
parent
0c85c8c60a
commit
e4e18b17b5
|
@ -165,16 +165,15 @@ public class SQLMetadataStorageActionHandler<EntryType, StatusType, LogType, Loc
|
|||
@Override
|
||||
public Optional<EntryType> withHandle(Handle handle) throws Exception
|
||||
{
|
||||
byte[] res = handle.createQuery(
|
||||
String.format("SELECT payload FROM %s WHERE id = :id", entryTable)
|
||||
)
|
||||
.bind("id", entryId)
|
||||
.map(ByteArrayMapper.FIRST)
|
||||
.first();
|
||||
|
||||
return Optional.fromNullable(
|
||||
jsonMapper.<EntryType>readValue(
|
||||
handle.createQuery(
|
||||
String.format("SELECT payload FROM %s WHERE id = :id", entryTable)
|
||||
)
|
||||
.bind("id", entryId)
|
||||
.map(ByteArrayMapper.FIRST)
|
||||
.first(),
|
||||
entryType
|
||||
)
|
||||
res == null ? null : jsonMapper.<EntryType>readValue(res, entryType)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -190,16 +189,15 @@ public class SQLMetadataStorageActionHandler<EntryType, StatusType, LogType, Loc
|
|||
@Override
|
||||
public Optional<StatusType> withHandle(Handle handle) throws Exception
|
||||
{
|
||||
byte[] res = handle.createQuery(
|
||||
String.format("SELECT status_payload FROM %s WHERE id = :id", entryTable)
|
||||
)
|
||||
.bind("id", entryId)
|
||||
.map(ByteArrayMapper.FIRST)
|
||||
.first();
|
||||
|
||||
return Optional.fromNullable(
|
||||
jsonMapper.<StatusType>readValue(
|
||||
handle.createQuery(
|
||||
String.format("SELECT status_payload FROM %s WHERE id = :id", entryTable)
|
||||
)
|
||||
.bind("id", entryId)
|
||||
.map(ByteArrayMapper.FIRST)
|
||||
.first(),
|
||||
statusType
|
||||
)
|
||||
res == null ? null : jsonMapper.<StatusType>readValue(res, statusType)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,8 +118,12 @@ public class SQLMetadataStorageActionHandlerTest
|
|||
handler.getEntry(entryId)
|
||||
);
|
||||
|
||||
Assert.assertEquals(Optional.absent(), handler.getEntry("non_exist_entry"));
|
||||
|
||||
Assert.assertEquals(Optional.absent(), handler.getStatus(entryId));
|
||||
|
||||
Assert.assertEquals(Optional.absent(), handler.getStatus("non_exist_entry"));
|
||||
|
||||
Assert.assertTrue(handler.setStatus(entryId, true, status1));
|
||||
|
||||
Assert.assertEquals(
|
||||
|
@ -179,6 +183,11 @@ public class SQLMetadataStorageActionHandlerTest
|
|||
|
||||
handler.insert(entryId, new DateTime("2014-01-01"), "test", entry, true, status);
|
||||
|
||||
Assert.assertEquals(
|
||||
ImmutableList.of(),
|
||||
handler.getLogs("non_exist_entry")
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
ImmutableMap.of(),
|
||||
handler.getLocks(entryId)
|
||||
|
@ -206,6 +215,11 @@ public class SQLMetadataStorageActionHandlerTest
|
|||
|
||||
handler.insert(entryId, new DateTime("2014-01-01"), "test", entry, true, status);
|
||||
|
||||
Assert.assertEquals(
|
||||
ImmutableMap.<Long, Map<String, Integer>>of(),
|
||||
handler.getLocks("non_exist_entry")
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
ImmutableMap.<Long, Map<String, Integer>>of(),
|
||||
handler.getLocks(entryId)
|
||||
|
|
Loading…
Reference in New Issue