2121import org .codehaus .jackson .JsonParser ;
2222import org .codehaus .jackson .map .ObjectMapper ;
2323import org .elasticsearch .hadoop .cfg .PropertiesSettings ;
24+ import org .elasticsearch .hadoop .rest .PartitionDefinition .PartitionDefinitionBuilder ;
2425import org .elasticsearch .hadoop .serialization .dto .mapping .FieldParser ;
2526import org .elasticsearch .hadoop .serialization .dto .mapping .Mapping ;
2627import org .elasticsearch .hadoop .util .BytesArray ;
3536import java .io .ObjectOutputStream ;
3637import java .util .Map ;
3738
38- import static org .junit .Assert .assertArrayEquals ;
39- import static org .junit .Assert .assertEquals ;
39+ import static org .junit .Assert .*;
4040
4141public class PartitionDefinitionTest {
4242
@@ -55,7 +55,7 @@ public void testWritable() throws IOException {
5555 PropertiesSettings settings = new PropertiesSettings ();
5656 settings .setProperty ("setting1" , "value1" );
5757 settings .setProperty ("setting2" , "value2" );
58- PartitionDefinition expected = new PartitionDefinition (settings , mapping , "foo" , 12 ,
58+ PartitionDefinition expected = PartitionDefinition . builder (settings , mapping ). build ( "foo" , 12 ,
5959 new String [] {"localhost:9200" , "otherhost:9200" });
6060 BytesArray bytes = writeWritablePartition (expected );
6161 PartitionDefinition def = readWritablePartition (bytes );
@@ -68,7 +68,7 @@ public void testSerializable() throws IOException, ClassNotFoundException {
6868 PropertiesSettings settings = new PropertiesSettings ();
6969 settings .setProperty ("setting1" , "value1" );
7070 settings .setProperty ("setting2" , "value2" );
71- PartitionDefinition expected = new PartitionDefinition (settings , mapping , "bar" , 37 ,
71+ PartitionDefinition expected = PartitionDefinition . builder (settings , mapping ). build ( "bar" , 37 ,
7272 new String [] {"localhost:9200" , "otherhost:9200" });
7373 BytesArray bytes = writeSerializablePartition (expected );
7474 PartitionDefinition def = readSerializablePartition (bytes );
@@ -81,7 +81,7 @@ public void testWritableWithSlice() throws IOException {
8181 PropertiesSettings settings = new PropertiesSettings ();
8282 settings .setProperty ("setting1" , "value1" );
8383 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 ),
8585 new String [] {"localhost:9200" , "otherhost:9200" });
8686 BytesArray bytes = writeWritablePartition (expected );
8787 PartitionDefinition def = readWritablePartition (bytes );
@@ -95,13 +95,35 @@ public void testSerializableWithSlice() throws IOException, ClassNotFoundExcepti
9595 settings .setProperty ("setting1" , "value1" );
9696 settings .setProperty ("setting2" , "value2" );
9797
98- PartitionDefinition expected = new PartitionDefinition (settings , mapping , "bar" , 37 ,
98+ PartitionDefinition expected = PartitionDefinition . builder (settings , mapping ). build ( "bar" , 37 ,
9999 new PartitionDefinition .Slice (13 , 35 ), new String [] {"localhost:9200" , "otherhost:9200" });
100100 BytesArray bytes = writeSerializablePartition (expected );
101101 PartitionDefinition def = readSerializablePartition (bytes );
102102 assertPartitionEquals (expected , def );
103103 }
104104
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+
105127 static PartitionDefinition readSerializablePartition (BytesArray bytes ) throws IOException , ClassNotFoundException {
106128 FastByteArrayInputStream in = new FastByteArrayInputStream (bytes );
107129 ObjectInputStream ois = new ObjectInputStream (in );
0 commit comments