mirror of https://github.com/apache/druid.git
Make MapBasedRow immutable (#7130)
* Make MapBasedRow immutable * add null check
This commit is contained in:
parent
a0afd7931d
commit
9a62157a06
|
@ -21,10 +21,12 @@ package org.apache.druid.data.input;
|
|||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.apache.druid.guice.annotations.PublicApi;
|
||||
import org.apache.druid.java.util.common.DateTimes;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -43,7 +45,7 @@ public class MapBasedRow implements Row
|
|||
)
|
||||
{
|
||||
this.timestamp = timestamp;
|
||||
this.event = event;
|
||||
this.event = Collections.unmodifiableMap(Preconditions.checkNotNull(event, "event"));
|
||||
}
|
||||
|
||||
public MapBasedRow(
|
||||
|
|
|
@ -22,10 +22,18 @@ package org.apache.druid.data.input;
|
|||
import com.google.common.collect.ImmutableMap;
|
||||
import org.apache.druid.java.util.common.DateTimes;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MapBasedRowTest
|
||||
{
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testGetLongMetricFromString()
|
||||
{
|
||||
|
@ -50,4 +58,15 @@ public class MapBasedRowTest
|
|||
Assert.assertEquals(-9223372036854775807L, row.getMetric("k5"));
|
||||
Assert.assertEquals(9223372036854775802L, row.getMetric("k6"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testImmutability()
|
||||
{
|
||||
final Map<String, Object> event = new HashMap<>();
|
||||
event.put("k0", 1);
|
||||
event.put("k1", 2);
|
||||
final MapBasedRow row = new MapBasedRow(DateTimes.nowUtc(), event);
|
||||
expectedException.expect(UnsupportedOperationException.class);
|
||||
row.getEvent().put("k2", 3);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue