@@ -535,6 +535,70 @@ describe('test VRP', () => {
535
535
done ) ;
536
536
} ) ;
537
537
538
+ it ( 'should be able to update a null suspended version in backward compatibility mode' , done => {
539
+ let nullVersionId ;
540
+
541
+ async . waterfall ( [ next => {
542
+ // simulate the creation of a null suspended version.
543
+ const request = {
544
+ db : 'foo' ,
545
+ key : 'bar' ,
546
+ value : '{"qux":"quz","isNull":true}' ,
547
+ options : {
548
+ versionId : '' ,
549
+ } ,
550
+ } ;
551
+ vrp . put ( request , logger , next ) ;
552
+ } ,
553
+ ( res , next ) => {
554
+ nullVersionId = JSON . parse ( res ) . versionId ;
555
+ // simulate update null version with BackbeatClient.putMetadata
556
+ const request = {
557
+ db : 'foo' ,
558
+ key : 'bar' ,
559
+ value : `{"qux":"quz2","isNull":true,"versionId":"${ nullVersionId } "}` ,
560
+ options : {
561
+ versioning : true ,
562
+ versionId : nullVersionId ,
563
+ } ,
564
+ } ;
565
+ vrp . put ( request , logger , next ) ;
566
+ } ,
567
+ ( res , next ) => {
568
+ wgm . list ( { } , logger , next ) ;
569
+ } ,
570
+ ( res , next ) => {
571
+ const expectedListing = [
572
+ // NOTE: should not set nullVersionId to the master version if updating a null version.
573
+ {
574
+ key : 'bar' ,
575
+ value : `{"qux":"quz2","isNull":true,"versionId":"${ nullVersionId } "}` ,
576
+ } ,
577
+ {
578
+ key : `bar\x00${ nullVersionId } ` ,
579
+ value : `{"qux":"quz","isNull":true,"versionId":"${ nullVersionId } "}` ,
580
+ } ,
581
+ ] ;
582
+ assert . deepStrictEqual ( res , expectedListing ) ;
583
+
584
+ const request = {
585
+ db : 'foo' ,
586
+ key : 'bar' ,
587
+ } ;
588
+ vrp . get ( request , logger , next ) ;
589
+ } ,
590
+ ( res , next ) => {
591
+ const expectedGet = {
592
+ qux : 'quz2' ,
593
+ isNull : true ,
594
+ versionId : nullVersionId ,
595
+ } ;
596
+ assert . deepStrictEqual ( JSON . parse ( res ) , expectedGet ) ;
597
+ next ( ) ;
598
+ } ] ,
599
+ done ) ;
600
+ } ) ;
601
+
538
602
it ( 'should delete the deprecated null key after put Metadata on top of an old null master' , done => {
539
603
const versionId = '00000000000000999999PARIS ' ;
540
604
let nullVersionId ;
@@ -592,8 +656,7 @@ describe('test VRP', () => {
592
656
// the null key
593
657
{
594
658
key : `bar${ VID_SEP } ` ,
595
- value : `{"qux":"quz2","isNull":true,"versionId":"${ nullVersionId } ",` +
596
- `"nullVersionId":"${ nullVersionId } ","isNull2":true}` ,
659
+ value : `{"qux":"quz2","isNull":true,"versionId":"${ nullVersionId } ","isNull2":true}` ,
597
660
} ,
598
661
// version key
599
662
{
@@ -691,6 +754,88 @@ describe('test VRP', () => {
691
754
} ] ,
692
755
done ) ;
693
756
} ) ;
757
+
758
+ it ( 'should delete the deprecated null key after updating a non-latest null key' , done => {
759
+ const versionId = '00000000000000999999PARIS ' ;
760
+ let nullVersionId ;
761
+
762
+ async . waterfall ( [ next => {
763
+ // simulate the creation of a null suspended version.
764
+ const request = {
765
+ db : 'foo' ,
766
+ key : 'bar' ,
767
+ value : '{"qux":"quz","isNull":true}' ,
768
+ options : {
769
+ versionId : '' ,
770
+ } ,
771
+ } ;
772
+ vrp . put ( request , logger , next ) ;
773
+ } ,
774
+ ( res , next ) => {
775
+ nullVersionId = JSON . parse ( res ) . versionId ;
776
+ // simulate a BackbeatClient.putMetadata
777
+ // null key is not the latest = master is not null.
778
+ const request = {
779
+ db : 'foo' ,
780
+ key : 'bar' ,
781
+ value : `{"qux":"quz2","versionId":"${ versionId } "}` ,
782
+ options : {
783
+ versioning : true ,
784
+ versionId,
785
+ } ,
786
+ } ;
787
+ vrp . put ( request , logger , next ) ;
788
+ } ,
789
+ ( res , next ) => {
790
+ // update the null version metadata with the new keys implementation (options.isNull defined)
791
+ const request = {
792
+ db : 'foo' ,
793
+ key : 'bar' ,
794
+ value : `{"qux":"quz3","isNull2":true,"isNull":true,"versionId":"${ nullVersionId } "}` ,
795
+ options : {
796
+ versionId : nullVersionId ,
797
+ isNull : true ,
798
+ } ,
799
+ } ;
800
+ vrp . put ( request , logger , next ) ;
801
+ } ,
802
+ ( res , next ) => {
803
+ wgm . list ( { } , logger , next ) ;
804
+ } ,
805
+ ( res , next ) => {
806
+ const expectedListing = [
807
+ {
808
+ key : 'bar' ,
809
+ value : `{"qux":"quz2","versionId":"${ versionId } ","nullVersionId":"${ nullVersionId } "}` ,
810
+ } ,
811
+ {
812
+ key : 'bar\x00' ,
813
+ value : `{"qux":"quz3","isNull2":true,"isNull":true,"versionId":"${ nullVersionId } "}` ,
814
+ } ,
815
+ {
816
+ key : `bar\x00${ versionId } ` ,
817
+ value : `{"qux":"quz2","versionId":"${ versionId } "}` ,
818
+ } ,
819
+ ] ;
820
+ assert . deepStrictEqual ( res , expectedListing ) ;
821
+
822
+ const request = {
823
+ db : 'foo' ,
824
+ key : 'bar' ,
825
+ } ;
826
+ vrp . get ( request , logger , next ) ;
827
+ } ,
828
+ ( res , next ) => {
829
+ const expectedGet = {
830
+ qux : 'quz2' ,
831
+ versionId,
832
+ nullVersionId,
833
+ } ;
834
+ assert . deepStrictEqual ( JSON . parse ( res ) , expectedGet ) ;
835
+ next ( ) ;
836
+ } ] ,
837
+ done ) ;
838
+ } ) ;
694
839
} ) ;
695
840
696
841
0 commit comments