@@ -15,6 +15,7 @@ package state
1515
1616import (
1717 "context"
18+ "encoding/base64"
1819 "encoding/json"
1920 "fmt"
2021 "slices"
@@ -784,6 +785,70 @@ func ConformanceTests(t *testing.T, props map[string]string, statestore state.St
784785 assert .Equal (t , v , res .Data )
785786 }
786787 })
788+
789+ t .Run ("transaction-serialization-grpc-json" , func (t * testing.T ) {
790+ features := statestore .Features ()
791+ // this check for exclude redis 7
792+ if state .FeatureQueryAPI .IsPresent (features ) {
793+ json := "{\" id\" :1223,\" name\" :\" test\" }"
794+ keyTest1 := key + "-key-grpc"
795+ valueTest := []byte (json )
796+ keyTest2 := key + "-key-grpc-no-json"
797+
798+ metadataTest1 := map [string ]string {
799+ "contentType" : "application/json" ,
800+ }
801+
802+ operations := []state.TransactionalStateOperation {
803+ state.SetRequest {
804+ Key : keyTest1 ,
805+ Value : valueTest ,
806+ Metadata : metadataTest1 ,
807+ },
808+ state.SetRequest {
809+ Key : keyTest2 ,
810+ Value : valueTest ,
811+ },
812+ }
813+
814+ expected := map [string ][]byte {
815+ keyTest1 : []byte (json ),
816+ keyTest2 : []byte (json ),
817+ }
818+
819+ expectedMetadata := map [string ]map [string ]string {
820+ keyTest1 : metadataTest1 ,
821+ }
822+
823+ // Act
824+ transactionStore , ok := statestore .(state.TransactionalStore )
825+ assert .True (t , ok )
826+ err := transactionStore .Multi (context .Background (), & state.TransactionalStateRequest {
827+ Operations : operations ,
828+ })
829+ require .NoError (t , err )
830+
831+ // Assert
832+ for k , v := range expected {
833+ res , err := statestore .Get (context .Background (), & state.GetRequest {
834+ Key : k ,
835+ Metadata : expectedMetadata [k ],
836+ })
837+ expectedValue := res .Data
838+
839+ // In redisjson when set the value with contentType = application/Json store the value in base64
840+ if strings .HasPrefix (string (expectedValue ), "\" ey" ) {
841+ valueBase64 := strings .Trim (string (expectedValue ), "\" " )
842+ expectedValueDecoded , _ := base64 .StdEncoding .DecodeString (valueBase64 )
843+ require .NoError (t , err )
844+ assert .Equal (t , expectedValueDecoded , v )
845+ } else {
846+ require .NoError (t , err )
847+ assert .Equal (t , expectedValue , v )
848+ }
849+ }
850+ }
851+ })
787852 } else {
788853 t .Run ("component does not implement TransactionalStore interface" , func (t * testing.T ) {
789854 _ , ok := statestore .(state.TransactionalStore )
0 commit comments