55import java .util .Arrays ;
66import java .util .List ;
77import java .util .Set ;
8+ import java .util .function .LongSupplier ;
89import java .util .stream .Collectors ;
910
1011import org .apache .accumulo .core .data .Key ;
@@ -49,6 +50,9 @@ public class ModelKeyParser {
4950 public static final String NULL_BYTE = "\0 " ;
5051 public static final Value NULL_VALUE = new Value (new byte [0 ]);
5152
53+ // Package-private to allow test override
54+ static LongSupplier clock = System ::currentTimeMillis ;
55+
5256 @ Deprecated
5357 public static final String INDEX_ONLY = "index_only" ;
5458
@@ -133,7 +137,7 @@ public static Key createKey(FieldMapping mapping, String modelName) {
133137 modelName + dataType , // ColFam
134138 outName + NULL_BYTE + mapping .getDirection ().getValue (), // ColQual
135139 cv , // Visibility
136- System . currentTimeMillis () // Timestamp
140+ clock . getAsLong () // Timestamp
137141 );
138142 } else {
139143 String fieldName = mapping .getModelFieldName () == null ? ModelKeyParser .MODEL : mapping .getModelFieldName ();
@@ -142,7 +146,7 @@ public static Key createKey(FieldMapping mapping, String modelName) {
142146 modelName + dataType , // ColFam
143147 attr , // ColQ
144148 cv , // Visibility
145- System . currentTimeMillis () // Timestamp
149+ clock . getAsLong () // Timestamp
146150 );
147151 }
148152 }
@@ -189,17 +193,16 @@ public static Mutation createMutation(FieldMapping mapping, String modelName) {
189193 if (Direction .REVERSE .equals (mapping .getDirection ())) {
190194 // Reverse mappings should not have indexOnly designators. If they do, scrub it off.
191195 m = new Mutation (mapping .getFieldName ());
192- m .put (modelName + dataType , mapping .getModelFieldName () + NULL_BYTE + mapping .getDirection ().getValue (), cv , System .currentTimeMillis (),
193- NULL_VALUE );
196+ m .put (modelName + dataType , mapping .getModelFieldName () + NULL_BYTE + mapping .getDirection ().getValue (), cv , clock .getAsLong (), NULL_VALUE );
194197 } else {
195198 m = new Mutation (mapping .getModelFieldName ());
196- m .put (modelName + dataType , mapping .getFieldName () + NULL_BYTE + mapping .getDirection ().getValue (), cv , System . currentTimeMillis (), NULL_VALUE );
199+ m .put (modelName + dataType , mapping .getFieldName () + NULL_BYTE + mapping .getDirection ().getValue (), cv , clock . getAsLong (), NULL_VALUE );
197200 }
198201 } else {
199202 String fieldName = mapping .getModelFieldName () == null ? ModelKeyParser .MODEL : mapping .getModelFieldName ();
200203 String [] attr = getAttrCqValue (mapping .getAttributes ());
201204 m = new Mutation (fieldName );
202- m .put (modelName + dataType , attr [0 ], cv , System . currentTimeMillis (), new Value (attr [1 ]));
205+ m .put (modelName + dataType , attr [0 ], cv , clock . getAsLong (), new Value (attr [1 ]));
203206 }
204207 return m ;
205208 }
@@ -212,24 +215,24 @@ public static Mutation createDeleteMutation(FieldMapping mapping, String modelNa
212215 if (mapping .isFieldMapping ()) {
213216 if (Direction .REVERSE .equals (mapping .getDirection ())) {
214217 m = new Mutation (mapping .getFieldName ());
215- m .putDelete (modelName + dataType , mapping .getModelFieldName () + NULL_BYTE + mapping .getDirection ().getValue (), cv , System . currentTimeMillis ());
218+ m .putDelete (modelName + dataType , mapping .getModelFieldName () + NULL_BYTE + mapping .getDirection ().getValue (), cv , clock . getAsLong ());
216219 } else {
217220 m = new Mutation (mapping .getModelFieldName ());
218- m .putDelete (modelName + dataType , mapping .getFieldName () + NULL_BYTE + mapping .getDirection ().getValue (), cv , System . currentTimeMillis ());
221+ m .putDelete (modelName + dataType , mapping .getFieldName () + NULL_BYTE + mapping .getDirection ().getValue (), cv , clock . getAsLong ());
219222 m .putDelete (modelName + dataType , mapping .getFieldName () + NULL_BYTE + INDEX_ONLY + NULL_BYTE + mapping .getDirection ().getValue (), cv ,
220- System . currentTimeMillis ());
223+ clock . getAsLong ());
221224 }
222225 } else {
223226 String fieldName = mapping .getModelFieldName () == null ? ModelKeyParser .MODEL : mapping .getModelFieldName ();
224227 m = new Mutation (fieldName );
225- m .putDelete (modelName + dataType , ATTRIBUTES , cv , System . currentTimeMillis ());
228+ m .putDelete (modelName + dataType , ATTRIBUTES , cv , clock . getAsLong ());
226229 if (mapping .getAttributes ().isEmpty ()) {
227- m .putDelete (modelName + dataType , "" , cv , System . currentTimeMillis ());
230+ m .putDelete (modelName + dataType , "" , cv , clock . getAsLong ());
228231 } else {
229232 for (String attr : mapping .getAttributes ()) {
230- m .putDelete (modelName + dataType , attr , cv , System . currentTimeMillis ());
233+ m .putDelete (modelName + dataType , attr , cv , clock . getAsLong ());
231234 if (attr .indexOf ('=' ) >= 0 ) {
232- m .putDelete (modelName + dataType , attr .substring (0 , attr .indexOf ('=' )), cv , System . currentTimeMillis ());
235+ m .putDelete (modelName + dataType , attr .substring (0 , attr .indexOf ('=' )), cv , clock . getAsLong ());
233236 }
234237 }
235238 }
0 commit comments