使用用于Jmeter

时间:2018-05-03 17:17:37

标签: mongodb groovy jmeter

我正在尝试使用Jmeter加载测试MongoDB,我正在使用JSR223Sampler使用Groovy,我能够连接但由于某种原因插入部分不工作  我需要在下面插入: “购物车”:{         “schema”:“http://dell.com/dcp/schemas/cart/3.0.0#”,         “_id”:“s5ChQonvAUGKM6s2Yq8Z31”,         “创建于” : {             “DateTime”:ISODate(“2018-03-07T06:54:01.242Z”),             “Ticks”:NumberLong(636560222412422269),             “抵消”:330         },         “lastModifiedOn”:{             “DateTime”:ISODate(“2018-03-07T06:54:01.245Z”),             “Ticks”:NumberLong(636560222412452266),             “抵消”:330         },         “到期” : {             “DateTime”:ISODate(“2019-04-10T08:21:43.984Z”),             “Ticks”:NumberLong(636904813039840000),             “抵消”:0         },         “commerceContext”:{             “地区”:“我们”,             “国家”:“美国”,             “语言”:“en”,             “货币:美元”,             “segment”:“bsd”,             “customerSet”:“rc1005388”,             “accessGroup”:“DSA”,             “companyNumber”:“08”,             “businessUnitId”:“11”,             “classCode”:“string”,             “sourceApplicationName”:“OLRGCOMM”         },         “项目”:[],         “发货”:[],         “价钱” : {          “couponCodes”:[]         },         “参考”:[             {                 “referenceId”:“8TOOOrdEJUeiGPTqWA226Q”,                 “referenceType”:“新推车”,                 “referencedOn”:{                     “DateTime”:ISODate(“2018-03-07T06:54:01.239Z”),                     “Ticks”:NumberLong(636560222412392112),                     “抵消”:330                 },                 “referenceCreatedBy”:“DCQO”,                 “targetSystem”:“DSP”,                 “目标”:“字符串”             }         ]         “验证”:{},         “属性”:{}     } })

1 个答案:

答案 0 :(得分:0)

  1. 首先,你需要从MongoDB Source Config获得MongoDB连接,它可以按如下方式完成:

    import com.mongodb.DB;
    import org.apache.jmeter.protocol.mongodb.config.MongoDBHolder;
    
    DB db = MongoDBHolder.getDBFromSource("mongodb source name", "database name");
    
  2. 接下来,您只需要调用DBCollection.insert()函数,如:

    db.getCollection('your collection name').insert(your DBObject payload here)
    
  3. 更多信息:How to Load Test MongoDB with JMeter