3535import feast .core .CoreServiceProto .ListStoresResponse ;
3636import feast .core .CoreServiceProto .UpdateStoreRequest ;
3737import feast .core .CoreServiceProto .UpdateStoreResponse ;
38+ import feast .core .FeatureSetProto ;
3839import feast .core .FeatureSetProto .FeatureSetSpec ;
3940import feast .core .FeatureSetProto .FeatureSpec ;
4041import feast .core .SourceProto .KafkaSourceConfig ;
6768
6869public class SpecServiceTest {
6970
70- @ Mock private FeatureSetRepository featureSetRepository ;
71+ @ Mock
72+ private FeatureSetRepository featureSetRepository ;
7173
72- @ Mock private StoreRepository storeRepository ;
74+ @ Mock
75+ private StoreRepository storeRepository ;
7376
74- @ Rule public final ExpectedException expectedException = ExpectedException .none ();
77+ @ Rule
78+ public final ExpectedException expectedException = ExpectedException .none ();
7579
7680 private SpecService specService ;
7781 private List <FeatureSet > featureSets ;
@@ -95,14 +99,25 @@ public void setUp() {
9599 FeatureSet featureSet1v3 = newDummyFeatureSet ("f1" , 3 );
96100 FeatureSet featureSet2v1 = newDummyFeatureSet ("f2" , 1 );
97101
98- featureSets = Arrays .asList (featureSet1v1 , featureSet1v2 , featureSet1v3 , featureSet2v1 );
102+ Field f3f1 = new Field ("f3" , "f3f1" , Enum .INT64 );
103+ Field f3f2 = new Field ("f3" , "f3f2" , Enum .INT64 );
104+ Field f3e1 = new Field ("f3" , "f3e1" , Enum .STRING );
105+ FeatureSet featureSet3v1 = new FeatureSet (
106+ "f3" , 1 , 100L , Arrays .asList (f3e1 ), Arrays .asList (f3f2 , f3f1 ), defaultSource );
107+
108+ featureSets = Arrays
109+ .asList (featureSet1v1 , featureSet1v2 , featureSet1v3 , featureSet2v1 , featureSet3v1 );
99110 when (featureSetRepository .findAll ()).thenReturn (featureSets );
111+ when (featureSetRepository .findAllByOrderByNameAscVersionAsc ()).thenReturn (featureSets );
100112 when (featureSetRepository .findByName ("f1" )).thenReturn (featureSets .subList (0 , 3 ));
113+ when (featureSetRepository .findByName ("f3" )).thenReturn (featureSets .subList (4 , 5 ));
101114 when (featureSetRepository .findFirstFeatureSetByNameOrderByVersionDesc ("f1" ))
102115 .thenReturn (featureSet1v3 );
103- when (featureSetRepository .findByNameWithWildcard ("f1" )).thenReturn (featureSets .subList (0 , 3 ));
116+ when (featureSetRepository .findByNameWithWildcardOrderByNameAscVersionAsc ("f1" ))
117+ .thenReturn (featureSets .subList (0 , 3 ));
104118 when (featureSetRepository .findByName ("asd" )).thenReturn (Lists .newArrayList ());
105- when (featureSetRepository .findByNameWithWildcard ("f%" )).thenReturn (featureSets );
119+ when (featureSetRepository .findByNameWithWildcardOrderByNameAscVersionAsc ("f%" ))
120+ .thenReturn (featureSets );
106121
107122 Store store1 = newDummyStore ("SERVING" );
108123 Store store2 = newDummyStore ("WAREHOUSE" );
@@ -238,7 +253,8 @@ public void shouldThrowExceptionGivenMissingFeatureSetName()
238253 @ Test
239254 public void shouldThrowExceptionGivenMissingFeatureSet () throws InvalidProtocolBufferException {
240255 expectedException .expect (StatusRuntimeException .class );
241- expectedException .expectMessage ("NOT_FOUND: Feature set could not be found" );
256+ expectedException .expectMessage (
257+ "NOT_FOUND: Feature set with name \" f1000\" and version \" 2\" could not be found." );
242258 specService .getFeatureSet (
243259 GetFeatureSetRequest .newBuilder ().setName ("f1000" ).setVersion (2 ).build ());
244260 }
@@ -331,6 +347,28 @@ public void applyFeatureSetShouldIncrementFeatureSetVersionIfAlreadyExists()
331347 assertThat (applyFeatureSetResponse .getFeatureSet (), equalTo (expected ));
332348 }
333349
350+
351+ @ Test
352+ public void applyFeatureSetShouldNotCreateFeatureSetIfFieldsUnordered ()
353+ throws InvalidProtocolBufferException {
354+
355+ Field f3f1 = new Field ("f3" , "f3f1" , Enum .INT64 );
356+ Field f3f2 = new Field ("f3" , "f3f2" , Enum .INT64 );
357+ Field f3e1 = new Field ("f3" , "f3e1" , Enum .STRING );
358+ FeatureSetProto .FeatureSetSpec incomingFeatureSet = (new FeatureSet (
359+ "f3" , 5 , 100L , Arrays .asList (f3e1 ), Arrays .asList (f3f2 , f3f1 ), defaultSource )).toProto ();
360+
361+ FeatureSetSpec expected = incomingFeatureSet ;
362+ ApplyFeatureSetResponse applyFeatureSetResponse =
363+ specService .applyFeatureSet (incomingFeatureSet );
364+ assertThat (applyFeatureSetResponse .getStatus (), equalTo (Status .NO_CHANGE ));
365+ assertThat (applyFeatureSetResponse .getFeatureSet ().getMaxAge (), equalTo (expected .getMaxAge ()));
366+ assertThat (applyFeatureSetResponse .getFeatureSet ().getEntities (0 ),
367+ equalTo (expected .getEntities (0 )));
368+ assertThat (applyFeatureSetResponse .getFeatureSet ().getName (), equalTo (expected .getName ()));
369+ }
370+
371+
334372 @ Test
335373 public void shouldUpdateStoreIfConfigChanges () throws InvalidProtocolBufferException {
336374 when (storeRepository .findById ("SERVING" )).thenReturn (Optional .of (stores .get (0 )));
0 commit comments