...

Text file src/go.mongodb.org/mongo-driver/testdata/sessions/snapshot-sessions.json

Documentation: go.mongodb.org/mongo-driver/testdata/sessions

     1{
     2  "description": "snapshot-sessions",
     3  "schemaVersion": "1.0",
     4  "runOnRequirements": [
     5    {
     6      "minServerVersion": "5.0",
     7      "topologies": [
     8        "replicaset",
     9        "sharded-replicaset"
    10      ]
    11    }
    12  ],
    13  "createEntities": [
    14    {
    15      "client": {
    16        "id": "client0",
    17        "observeEvents": [
    18          "commandStartedEvent"
    19        ],
    20        "ignoreCommandMonitoringEvents": [
    21          "findAndModify",
    22          "insert",
    23          "update"
    24        ]
    25      }
    26    },
    27    {
    28      "database": {
    29        "id": "database0",
    30        "client": "client0",
    31        "databaseName": "database0"
    32      }
    33    },
    34    {
    35      "collection": {
    36        "id": "collection0",
    37        "database": "database0",
    38        "collectionName": "collection0",
    39        "collectionOptions": {
    40          "writeConcern": {
    41            "w": "majority"
    42          }
    43        }
    44      }
    45    },
    46    {
    47      "session": {
    48        "id": "session0",
    49        "client": "client0",
    50        "sessionOptions": {
    51          "snapshot": true
    52        }
    53      }
    54    },
    55    {
    56      "session": {
    57        "id": "session1",
    58        "client": "client0",
    59        "sessionOptions": {
    60          "snapshot": true
    61        }
    62      }
    63    }
    64  ],
    65  "initialData": [
    66    {
    67      "collectionName": "collection0",
    68      "databaseName": "database0",
    69      "documents": [
    70        {
    71          "_id": 1,
    72          "x": 11
    73        },
    74        {
    75          "_id": 2,
    76          "x": 11
    77        }
    78      ]
    79    }
    80  ],
    81  "tests": [
    82    {
    83      "description": "Find operation with snapshot",
    84      "operations": [
    85        {
    86          "name": "find",
    87          "object": "collection0",
    88          "arguments": {
    89            "session": "session0",
    90            "filter": {
    91              "_id": 1
    92            }
    93          },
    94          "expectResult": [
    95            {
    96              "_id": 1,
    97              "x": 11
    98            }
    99          ]
   100        },
   101        {
   102          "name": "findOneAndUpdate",
   103          "object": "collection0",
   104          "arguments": {
   105            "filter": {
   106              "_id": 1
   107            },
   108            "update": {
   109              "$inc": {
   110                "x": 1
   111              }
   112            },
   113            "returnDocument": "After"
   114          },
   115          "expectResult": {
   116            "_id": 1,
   117            "x": 12
   118          }
   119        },
   120        {
   121          "name": "find",
   122          "object": "collection0",
   123          "arguments": {
   124            "session": "session1",
   125            "filter": {
   126              "_id": 1
   127            }
   128          },
   129          "expectResult": [
   130            {
   131              "_id": 1,
   132              "x": 12
   133            }
   134          ]
   135        },
   136        {
   137          "name": "findOneAndUpdate",
   138          "object": "collection0",
   139          "arguments": {
   140            "filter": {
   141              "_id": 1
   142            },
   143            "update": {
   144              "$inc": {
   145                "x": 1
   146              }
   147            },
   148            "returnDocument": "After"
   149          },
   150          "expectResult": {
   151            "_id": 1,
   152            "x": 13
   153          }
   154        },
   155        {
   156          "name": "find",
   157          "object": "collection0",
   158          "arguments": {
   159            "filter": {
   160              "_id": 1
   161            }
   162          },
   163          "expectResult": [
   164            {
   165              "_id": 1,
   166              "x": 13
   167            }
   168          ]
   169        },
   170        {
   171          "name": "find",
   172          "object": "collection0",
   173          "arguments": {
   174            "session": "session0",
   175            "filter": {
   176              "_id": 1
   177            }
   178          },
   179          "expectResult": [
   180            {
   181              "_id": 1,
   182              "x": 11
   183            }
   184          ]
   185        },
   186        {
   187          "name": "find",
   188          "object": "collection0",
   189          "arguments": {
   190            "session": "session1",
   191            "filter": {
   192              "_id": 1
   193            }
   194          },
   195          "expectResult": [
   196            {
   197              "_id": 1,
   198              "x": 12
   199            }
   200          ]
   201        }
   202      ],
   203      "expectEvents": [
   204        {
   205          "client": "client0",
   206          "events": [
   207            {
   208              "commandStartedEvent": {
   209                "command": {
   210                  "find": "collection0",
   211                  "readConcern": {
   212                    "level": "snapshot",
   213                    "atClusterTime": {
   214                      "$$exists": false
   215                    }
   216                  }
   217                }
   218              }
   219            },
   220            {
   221              "commandStartedEvent": {
   222                "command": {
   223                  "find": "collection0",
   224                  "readConcern": {
   225                    "level": "snapshot",
   226                    "atClusterTime": {
   227                      "$$exists": false
   228                    }
   229                  }
   230                }
   231              }
   232            },
   233            {
   234              "commandStartedEvent": {
   235                "command": {
   236                  "find": "collection0",
   237                  "readConcern": {
   238                    "$$exists": false
   239                  }
   240                }
   241              }
   242            },
   243            {
   244              "commandStartedEvent": {
   245                "command": {
   246                  "find": "collection0",
   247                  "readConcern": {
   248                    "level": "snapshot",
   249                    "atClusterTime": {
   250                      "$$exists": true
   251                    }
   252                  }
   253                }
   254              }
   255            },
   256            {
   257              "commandStartedEvent": {
   258                "command": {
   259                  "find": "collection0",
   260                  "readConcern": {
   261                    "level": "snapshot",
   262                    "atClusterTime": {
   263                      "$$exists": true
   264                    }
   265                  }
   266                }
   267              }
   268            }
   269          ]
   270        }
   271      ]
   272    },
   273    {
   274      "description": "Distinct operation with snapshot",
   275      "operations": [
   276        {
   277          "name": "distinct",
   278          "object": "collection0",
   279          "arguments": {
   280            "fieldName": "x",
   281            "filter": {},
   282            "session": "session0"
   283          },
   284          "expectResult": [
   285            11
   286          ]
   287        },
   288        {
   289          "name": "findOneAndUpdate",
   290          "object": "collection0",
   291          "arguments": {
   292            "filter": {
   293              "_id": 2
   294            },
   295            "update": {
   296              "$inc": {
   297                "x": 1
   298              }
   299            },
   300            "returnDocument": "After"
   301          },
   302          "expectResult": {
   303            "_id": 2,
   304            "x": 12
   305          }
   306        },
   307        {
   308          "name": "distinct",
   309          "object": "collection0",
   310          "arguments": {
   311            "fieldName": "x",
   312            "filter": {},
   313            "session": "session1"
   314          },
   315          "expectResult": [
   316            11,
   317            12
   318          ]
   319        },
   320        {
   321          "name": "findOneAndUpdate",
   322          "object": "collection0",
   323          "arguments": {
   324            "filter": {
   325              "_id": 2
   326            },
   327            "update": {
   328              "$inc": {
   329                "x": 1
   330              }
   331            },
   332            "returnDocument": "After"
   333          },
   334          "expectResult": {
   335            "_id": 2,
   336            "x": 13
   337          }
   338        },
   339        {
   340          "name": "distinct",
   341          "object": "collection0",
   342          "arguments": {
   343            "fieldName": "x",
   344            "filter": {}
   345          },
   346          "expectResult": [
   347            11,
   348            13
   349          ]
   350        },
   351        {
   352          "name": "distinct",
   353          "object": "collection0",
   354          "arguments": {
   355            "fieldName": "x",
   356            "filter": {},
   357            "session": "session0"
   358          },
   359          "expectResult": [
   360            11
   361          ]
   362        },
   363        {
   364          "name": "distinct",
   365          "object": "collection0",
   366          "arguments": {
   367            "fieldName": "x",
   368            "filter": {},
   369            "session": "session1"
   370          },
   371          "expectResult": [
   372            11,
   373            12
   374          ]
   375        }
   376      ],
   377      "expectEvents": [
   378        {
   379          "client": "client0",
   380          "events": [
   381            {
   382              "commandStartedEvent": {
   383                "command": {
   384                  "distinct": "collection0",
   385                  "readConcern": {
   386                    "level": "snapshot",
   387                    "atClusterTime": {
   388                      "$$exists": false
   389                    }
   390                  }
   391                }
   392              }
   393            },
   394            {
   395              "commandStartedEvent": {
   396                "command": {
   397                  "distinct": "collection0",
   398                  "readConcern": {
   399                    "level": "snapshot",
   400                    "atClusterTime": {
   401                      "$$exists": false
   402                    }
   403                  }
   404                }
   405              }
   406            },
   407            {
   408              "commandStartedEvent": {
   409                "command": {
   410                  "distinct": "collection0",
   411                  "readConcern": {
   412                    "$$exists": false
   413                  }
   414                }
   415              }
   416            },
   417            {
   418              "commandStartedEvent": {
   419                "command": {
   420                  "distinct": "collection0",
   421                  "readConcern": {
   422                    "level": "snapshot",
   423                    "atClusterTime": {
   424                      "$$exists": true
   425                    }
   426                  }
   427                }
   428              }
   429            },
   430            {
   431              "commandStartedEvent": {
   432                "command": {
   433                  "distinct": "collection0",
   434                  "readConcern": {
   435                    "level": "snapshot",
   436                    "atClusterTime": {
   437                      "$$exists": true
   438                    }
   439                  }
   440                }
   441              }
   442            }
   443          ]
   444        }
   445      ]
   446    },
   447    {
   448      "description": "Aggregate operation with snapshot",
   449      "operations": [
   450        {
   451          "name": "aggregate",
   452          "object": "collection0",
   453          "arguments": {
   454            "pipeline": [
   455              {
   456                "$match": {
   457                  "_id": 1
   458                }
   459              }
   460            ],
   461            "session": "session0"
   462          },
   463          "expectResult": [
   464            {
   465              "_id": 1,
   466              "x": 11
   467            }
   468          ]
   469        },
   470        {
   471          "name": "findOneAndUpdate",
   472          "object": "collection0",
   473          "arguments": {
   474            "filter": {
   475              "_id": 1
   476            },
   477            "update": {
   478              "$inc": {
   479                "x": 1
   480              }
   481            },
   482            "returnDocument": "After"
   483          },
   484          "expectResult": {
   485            "_id": 1,
   486            "x": 12
   487          }
   488        },
   489        {
   490          "name": "aggregate",
   491          "object": "collection0",
   492          "arguments": {
   493            "pipeline": [
   494              {
   495                "$match": {
   496                  "_id": 1
   497                }
   498              }
   499            ],
   500            "session": "session1"
   501          },
   502          "expectResult": [
   503            {
   504              "_id": 1,
   505              "x": 12
   506            }
   507          ]
   508        },
   509        {
   510          "name": "findOneAndUpdate",
   511          "object": "collection0",
   512          "arguments": {
   513            "filter": {
   514              "_id": 1
   515            },
   516            "update": {
   517              "$inc": {
   518                "x": 1
   519              }
   520            },
   521            "returnDocument": "After"
   522          },
   523          "expectResult": {
   524            "_id": 1,
   525            "x": 13
   526          }
   527        },
   528        {
   529          "name": "aggregate",
   530          "object": "collection0",
   531          "arguments": {
   532            "pipeline": [
   533              {
   534                "$match": {
   535                  "_id": 1
   536                }
   537              }
   538            ]
   539          },
   540          "expectResult": [
   541            {
   542              "_id": 1,
   543              "x": 13
   544            }
   545          ]
   546        },
   547        {
   548          "name": "aggregate",
   549          "object": "collection0",
   550          "arguments": {
   551            "pipeline": [
   552              {
   553                "$match": {
   554                  "_id": 1
   555                }
   556              }
   557            ],
   558            "session": "session0"
   559          },
   560          "expectResult": [
   561            {
   562              "_id": 1,
   563              "x": 11
   564            }
   565          ]
   566        },
   567        {
   568          "name": "aggregate",
   569          "object": "collection0",
   570          "arguments": {
   571            "pipeline": [
   572              {
   573                "$match": {
   574                  "_id": 1
   575                }
   576              }
   577            ],
   578            "session": "session1"
   579          },
   580          "expectResult": [
   581            {
   582              "_id": 1,
   583              "x": 12
   584            }
   585          ]
   586        }
   587      ],
   588      "expectEvents": [
   589        {
   590          "client": "client0",
   591          "events": [
   592            {
   593              "commandStartedEvent": {
   594                "command": {
   595                  "aggregate": "collection0",
   596                  "readConcern": {
   597                    "level": "snapshot",
   598                    "atClusterTime": {
   599                      "$$exists": false
   600                    }
   601                  }
   602                }
   603              }
   604            },
   605            {
   606              "commandStartedEvent": {
   607                "command": {
   608                  "aggregate": "collection0",
   609                  "readConcern": {
   610                    "level": "snapshot",
   611                    "atClusterTime": {
   612                      "$$exists": false
   613                    }
   614                  }
   615                }
   616              }
   617            },
   618            {
   619              "commandStartedEvent": {
   620                "command": {
   621                  "aggregate": "collection0",
   622                  "readConcern": {
   623                    "$$exists": false
   624                  }
   625                }
   626              }
   627            },
   628            {
   629              "commandStartedEvent": {
   630                "command": {
   631                  "aggregate": "collection0",
   632                  "readConcern": {
   633                    "level": "snapshot",
   634                    "atClusterTime": {
   635                      "$$exists": true
   636                    }
   637                  }
   638                }
   639              }
   640            },
   641            {
   642              "commandStartedEvent": {
   643                "command": {
   644                  "aggregate": "collection0",
   645                  "readConcern": {
   646                    "level": "snapshot",
   647                    "atClusterTime": {
   648                      "$$exists": true
   649                    }
   650                  }
   651                }
   652              }
   653            }
   654          ]
   655        }
   656      ]
   657    },
   658    {
   659      "description": "countDocuments operation with snapshot",
   660      "operations": [
   661        {
   662          "name": "countDocuments",
   663          "object": "collection0",
   664          "arguments": {
   665            "filter": {},
   666            "session": "session0"
   667          },
   668          "expectResult": 2
   669        },
   670        {
   671          "name": "countDocuments",
   672          "object": "collection0",
   673          "arguments": {
   674            "filter": {},
   675            "session": "session0"
   676          },
   677          "expectResult": 2
   678        }
   679      ],
   680      "expectEvents": [
   681        {
   682          "client": "client0",
   683          "events": [
   684            {
   685              "commandStartedEvent": {
   686                "command": {
   687                  "aggregate": "collection0",
   688                  "readConcern": {
   689                    "level": "snapshot",
   690                    "atClusterTime": {
   691                      "$$exists": false
   692                    }
   693                  }
   694                }
   695              }
   696            },
   697            {
   698              "commandStartedEvent": {
   699                "command": {
   700                  "aggregate": "collection0",
   701                  "readConcern": {
   702                    "level": "snapshot",
   703                    "atClusterTime": {
   704                      "$$exists": true
   705                    }
   706                  }
   707                }
   708              }
   709            }
   710          ]
   711        }
   712      ]
   713    },
   714    {
   715      "description": "Mixed operation with snapshot",
   716      "operations": [
   717        {
   718          "name": "find",
   719          "object": "collection0",
   720          "arguments": {
   721            "session": "session0",
   722            "filter": {
   723              "_id": 1
   724            }
   725          },
   726          "expectResult": [
   727            {
   728              "_id": 1,
   729              "x": 11
   730            }
   731          ]
   732        },
   733        {
   734          "name": "findOneAndUpdate",
   735          "object": "collection0",
   736          "arguments": {
   737            "filter": {
   738              "_id": 1
   739            },
   740            "update": {
   741              "$inc": {
   742                "x": 1
   743              }
   744            },
   745            "returnDocument": "After"
   746          },
   747          "expectResult": {
   748            "_id": 1,
   749            "x": 12
   750          }
   751        },
   752        {
   753          "name": "find",
   754          "object": "collection0",
   755          "arguments": {
   756            "filter": {
   757              "_id": 1
   758            }
   759          },
   760          "expectResult": [
   761            {
   762              "_id": 1,
   763              "x": 12
   764            }
   765          ]
   766        },
   767        {
   768          "name": "aggregate",
   769          "object": "collection0",
   770          "arguments": {
   771            "pipeline": [
   772              {
   773                "$match": {
   774                  "_id": 1
   775                }
   776              }
   777            ],
   778            "session": "session0"
   779          },
   780          "expectResult": [
   781            {
   782              "_id": 1,
   783              "x": 11
   784            }
   785          ]
   786        },
   787        {
   788          "name": "distinct",
   789          "object": "collection0",
   790          "arguments": {
   791            "fieldName": "x",
   792            "filter": {},
   793            "session": "session0"
   794          },
   795          "expectResult": [
   796            11
   797          ]
   798        }
   799      ],
   800      "expectEvents": [
   801        {
   802          "client": "client0",
   803          "events": [
   804            {
   805              "commandStartedEvent": {
   806                "command": {
   807                  "find": "collection0",
   808                  "readConcern": {
   809                    "level": "snapshot",
   810                    "atClusterTime": {
   811                      "$$exists": false
   812                    }
   813                  }
   814                }
   815              }
   816            },
   817            {
   818              "commandStartedEvent": {
   819                "command": {
   820                  "find": "collection0",
   821                  "readConcern": {
   822                    "$$exists": false
   823                  }
   824                }
   825              }
   826            },
   827            {
   828              "commandStartedEvent": {
   829                "command": {
   830                  "aggregate": "collection0",
   831                  "readConcern": {
   832                    "level": "snapshot",
   833                    "atClusterTime": {
   834                      "$$exists": true
   835                    }
   836                  }
   837                }
   838              }
   839            },
   840            {
   841              "commandStartedEvent": {
   842                "command": {
   843                  "distinct": "collection0",
   844                  "readConcern": {
   845                    "level": "snapshot",
   846                    "atClusterTime": {
   847                      "$$exists": true
   848                    }
   849                  }
   850                }
   851              }
   852            }
   853          ]
   854        }
   855      ]
   856    },
   857    {
   858      "description": "Write commands with snapshot session do not affect snapshot reads",
   859      "operations": [
   860        {
   861          "name": "find",
   862          "object": "collection0",
   863          "arguments": {
   864            "filter": {},
   865            "session": "session0"
   866          }
   867        },
   868        {
   869          "name": "insertOne",
   870          "object": "collection0",
   871          "arguments": {
   872            "document": {
   873              "_id": 22,
   874              "x": 33
   875            }
   876          }
   877        },
   878        {
   879          "name": "updateOne",
   880          "object": "collection0",
   881          "arguments": {
   882            "filter": {
   883              "_id": 1
   884            },
   885            "update": {
   886              "$inc": {
   887                "x": 1
   888              }
   889            }
   890          }
   891        },
   892        {
   893          "name": "find",
   894          "object": "collection0",
   895          "arguments": {
   896            "filter": {
   897              "_id": 1
   898            },
   899            "session": "session0"
   900          },
   901          "expectResult": [
   902            {
   903              "_id": 1,
   904              "x": 11
   905            }
   906          ]
   907        }
   908      ],
   909      "expectEvents": [
   910        {
   911          "client": "client0",
   912          "events": [
   913            {
   914              "commandStartedEvent": {
   915                "command": {
   916                  "find": "collection0",
   917                  "readConcern": {
   918                    "level": "snapshot",
   919                    "atClusterTime": {
   920                      "$$exists": false
   921                    }
   922                  }
   923                }
   924              }
   925            },
   926            {
   927              "commandStartedEvent": {
   928                "command": {
   929                  "find": "collection0",
   930                  "readConcern": {
   931                    "level": "snapshot",
   932                    "atClusterTime": {
   933                      "$$exists": true
   934                    }
   935                  }
   936                }
   937              }
   938            }
   939          ]
   940        }
   941      ]
   942    },
   943    {
   944      "description": "First snapshot read does not send atClusterTime",
   945      "operations": [
   946        {
   947          "name": "find",
   948          "object": "collection0",
   949          "arguments": {
   950            "filter": {},
   951            "session": "session0"
   952          }
   953        }
   954      ],
   955      "expectEvents": [
   956        {
   957          "client": "client0",
   958          "events": [
   959            {
   960              "commandStartedEvent": {
   961                "command": {
   962                  "find": "collection0",
   963                  "readConcern": {
   964                    "level": "snapshot",
   965                    "atClusterTime": {
   966                      "$$exists": false
   967                    }
   968                  }
   969                },
   970                "commandName": "find",
   971                "databaseName": "database0"
   972              }
   973            }
   974          ]
   975        }
   976      ]
   977    },
   978    {
   979      "description": "StartTransaction fails in snapshot session",
   980      "operations": [
   981        {
   982          "name": "startTransaction",
   983          "object": "session0",
   984          "expectError": {
   985            "isError": true,
   986            "isClientError": true,
   987            "errorContains": "Transactions are not supported in snapshot sessions"
   988          }
   989        }
   990      ]
   991    }
   992  ]
   993}

View as plain text