Skip to content

Instantly share code, notes, and snippets.

View jyemin's full-sized avatar

Jeff Yemin jyemin

View GitHub Profile
@jyemin
jyemin / MongoUpsertContentionTest
Created March 27, 2012 02:52
Program for benchmarking upserts using the Java driver
import com.mongodb.*;
import org.bson.types.ObjectId;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/*
* Copyright (c) 2008 - 2012 10gen, Inc. <http://10gen.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
com.sun.security.jgss.krb5.initiate {
com.sun.security.auth.module.Krb5LoginModule required
doNotPrompt=true useKeyTab=true principal=user1;
};
@jyemin
jyemin / AndQueryTest.java
Created March 25, 2014 02:39
This test shows that range queries over a date work properly both with and without the use of $and operator
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.QueryBuilder;
import java.net.UnknownHostException;
import java.util.Date;
public class AndQueryTest {
@jyemin
jyemin / MongoDBWithJodaExample.java
Created July 16, 2014 16:57
An example showing how to integrate support for Joda DateTime into the MongoDB Java driver.
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import org.bson.BSON;
import org.bson.Transformer;
import org.joda.time.DateTime;
import java.net.UnknownHostException;
import java.util.Date;
@jyemin
jyemin / ClassCastException.cs
Last active August 29, 2015 14:13
Class Cast Hell
var doc = new BsonDocument("x", 10.0);
var x1 = doc["x"].AsInt32; // breaks
var x2 = (int)doc["x"]; // breaks
var x3 = doc["x"].ToInt32(); // ok
@jyemin
jyemin / AsyncIsNotBlockingTest.java
Created December 4, 2015 14:58
Test demonstrating that asynchronous operations do not block even if the number of active operations exceeds the maximum pool size.
/*
* Copyright 2015 MongoDB Inc. <http://10gen.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/*
* Copyright (c) 2015 MongoDB, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/*
* Copyright (c) 2008 - 2013 10gen, Inc. <http://10gen.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/*
* Copyright (c) 2008 - 2013 10gen, Inc. <http://10gen.com>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software