21
21
import org .codehaus .jackson .JsonParser ;
22
22
import org .codehaus .jackson .map .ObjectMapper ;
23
23
import org .elasticsearch .hadoop .cfg .PropertiesSettings ;
24
+ import org .elasticsearch .hadoop .rest .PartitionDefinition .PartitionDefinitionBuilder ;
24
25
import org .elasticsearch .hadoop .serialization .dto .mapping .FieldParser ;
25
26
import org .elasticsearch .hadoop .serialization .dto .mapping .Mapping ;
26
27
import org .elasticsearch .hadoop .util .BytesArray ;
35
36
import java .io .ObjectOutputStream ;
36
37
import java .util .Map ;
37
38
38
- import static org .junit .Assert .assertArrayEquals ;
39
- import static org .junit .Assert .assertEquals ;
39
+ import static org .junit .Assert .*;
40
40
41
41
public class PartitionDefinitionTest {
42
42
@@ -55,7 +55,7 @@ public void testWritable() throws IOException {
55
55
PropertiesSettings settings = new PropertiesSettings ();
56
56
settings .setProperty ("setting1" , "value1" );
57
57
settings .setProperty ("setting2" , "value2" );
58
- PartitionDefinition expected = new PartitionDefinition (settings , mapping , "foo" , 12 ,
58
+ PartitionDefinition expected = PartitionDefinition . builder (settings , mapping ). build ( "foo" , 12 ,
59
59
new String [] {"localhost:9200" , "otherhost:9200" });
60
60
BytesArray bytes = writeWritablePartition (expected );
61
61
PartitionDefinition def = readWritablePartition (bytes );
@@ -68,7 +68,7 @@ public void testSerializable() throws IOException, ClassNotFoundException {
68
68
PropertiesSettings settings = new PropertiesSettings ();
69
69
settings .setProperty ("setting1" , "value1" );
70
70
settings .setProperty ("setting2" , "value2" );
71
- PartitionDefinition expected = new PartitionDefinition (settings , mapping , "bar" , 37 ,
71
+ PartitionDefinition expected = PartitionDefinition . builder (settings , mapping ). build ( "bar" , 37 ,
72
72
new String [] {"localhost:9200" , "otherhost:9200" });
73
73
BytesArray bytes = writeSerializablePartition (expected );
74
74
PartitionDefinition def = readSerializablePartition (bytes );
@@ -81,7 +81,7 @@ public void testWritableWithSlice() throws IOException {
81
81
PropertiesSettings settings = new PropertiesSettings ();
82
82
settings .setProperty ("setting1" , "value1" );
83
83
settings .setProperty ("setting2" , "value2" );
84
- PartitionDefinition expected = new PartitionDefinition (settings , mapping , "foo" , 12 , new PartitionDefinition .Slice (10 , 27 ),
84
+ PartitionDefinition expected = PartitionDefinition . builder (settings , mapping ). build ( "foo" , 12 , new PartitionDefinition .Slice (10 , 27 ),
85
85
new String [] {"localhost:9200" , "otherhost:9200" });
86
86
BytesArray bytes = writeWritablePartition (expected );
87
87
PartitionDefinition def = readWritablePartition (bytes );
@@ -95,13 +95,35 @@ public void testSerializableWithSlice() throws IOException, ClassNotFoundExcepti
95
95
settings .setProperty ("setting1" , "value1" );
96
96
settings .setProperty ("setting2" , "value2" );
97
97
98
- PartitionDefinition expected = new PartitionDefinition (settings , mapping , "bar" , 37 ,
98
+ PartitionDefinition expected = PartitionDefinition . builder (settings , mapping ). build ( "bar" , 37 ,
99
99
new PartitionDefinition .Slice (13 , 35 ), new String [] {"localhost:9200" , "otherhost:9200" });
100
100
BytesArray bytes = writeSerializablePartition (expected );
101
101
PartitionDefinition def = readSerializablePartition (bytes );
102
102
assertPartitionEquals (expected , def );
103
103
}
104
104
105
+ @ Test
106
+ public void testNonDuplicationOfConfiguration () throws IOException {
107
+ Mapping mapping = getTestMapping ();
108
+ PropertiesSettings settings = new PropertiesSettings ();
109
+ settings .setProperty ("setting1" , "value1" );
110
+ settings .setProperty ("setting2" , "value2" );
111
+ PartitionDefinitionBuilder partitionBuilder = PartitionDefinition .builder (settings , mapping );
112
+
113
+ PartitionDefinition first = partitionBuilder .build ("foo" , 11 ,
114
+ new String [] {"localhost:9200" , "otherhost:9200" });
115
+ PartitionDefinition second = partitionBuilder .build ("foo" , 12 ,
116
+ new String [] {"localhost:9200" , "otherhost:9200" });
117
+ assertNotEquals (first , second );
118
+ assertSame (first .getSerializedSettings (), second .getSerializedSettings ());
119
+ assertSame (first .getSerializedMapping (), second .getSerializedMapping ());
120
+ BytesArray bytes = writeWritablePartition (first );
121
+ PartitionDefinition def = readWritablePartition (bytes );
122
+ assertPartitionEquals (first , def );
123
+ assertNotSame (first .getSerializedSettings (), def .getSerializedSettings ());
124
+ assertNotSame (first .getSerializedMapping (), def .getSerializedMapping ());
125
+ }
126
+
105
127
static PartitionDefinition readSerializablePartition (BytesArray bytes ) throws IOException , ClassNotFoundException {
106
128
FastByteArrayInputStream in = new FastByteArrayInputStream (bytes );
107
129
ObjectInputStream ois = new ObjectInputStream (in );
0 commit comments