|
| 1 | +/* |
| 2 | + * Copyright (c) 2008 - 2013 10gen, Inc. <http://10gen.com> |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + */ |
| 17 | + |
| 18 | +package com.mongodb; |
| 19 | + |
| 20 | +import com.mongodb.util.TestCase; |
| 21 | +import org.testng.annotations.Test; |
| 22 | + |
| 23 | +import java.io.IOException; |
| 24 | +import java.util.Arrays; |
| 25 | + |
| 26 | +public class DBApiLayerTest extends TestCase { |
| 27 | + private final DBApiLayer db; |
| 28 | + |
| 29 | + public DBApiLayerTest() throws IOException, MongoException { |
| 30 | + super(); |
| 31 | + cleanupDB = "com_mongodb_unittest_DBApiLayerTest"; |
| 32 | + db = (DBApiLayer) cleanupMongo.getDB( cleanupDB ); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testCursorNotFoundException() { |
| 37 | + DBCollection collection = db.getCollection("testCursorNotFoundException"); |
| 38 | + for (int i = 0; i < 150; i++) { |
| 39 | + collection.insert(new BasicDBObject()); |
| 40 | + } |
| 41 | + |
| 42 | + DBCursor cursor = collection.find(); |
| 43 | + cursor.next(); // force the query |
| 44 | + |
| 45 | + db.killCursors(cursor.getServerAddress(), Arrays.asList(cursor.getCursorId())); |
| 46 | + |
| 47 | + try { |
| 48 | + while (cursor.hasNext()) { |
| 49 | + cursor.next(); |
| 50 | + } |
| 51 | + fail("Cursor die!"); |
| 52 | + } catch (MongoException.CursorNotFound e) { |
| 53 | + assertEquals(cursor.getServerAddress(), e.getServerAddress()); |
| 54 | + assertEquals(cursor.getCursorId(), e.getCursorId()); |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments