Package com.mongodb

Examples of com.mongodb.MongoException$CursorNotFound


  }

  @Test(expected = DataAccessException.class)
  public void removeHandlesMongoExceptionProperly() throws Exception {
    MongoTemplate template = mockOutGetDb();
    when(db.getCollection("collection")).thenThrow(new MongoException("Exception!"));

    template.remove(null, "collection");
  }
View Full Code Here


    * @see org.springframework.data.mongodb.core.core.MongoOperationsUnitTests#getOperations()
    */
  @Override
  protected MongoOperations getOperationsForExceptionHandling() {
    MongoTemplate template = spy(this.template);
    stub(template.getDb()).toThrow(new MongoException("Error!"));
    return template;
  }
View Full Code Here

    db = mongo.getDB(conf.getNamespace());

    if (requiresAuthentication(mongo)) {
      if (!mongo.getDB("admin").authenticate(conf.getDatabaseUser(),
          conf.getDatabasePassword().toCharArray())) {
        throw new ConnectionException(new MongoException(
            "Failed to authenticate to MongoDB with username="
                + conf.getDatabaseUser()));
      }
    }
View Full Code Here

            Collection<T> collection, String key,
            DocumentReadPreference docReadPref,
            int retries) {
        checkArgument(retries >= 0, "retries must not be negative");
        int numAttempts = retries + 1;
        MongoException ex = null;
        for (int i = 0; i < numAttempts; i++) {
            if (i > 0) {
                LOG.warn("Retrying read of " + key);
            }
            try {
View Full Code Here

        protected <T extends Document> T findUncached(Collection<T> collection,
                                                      String key,
                                                      DocumentReadPreference docReadPref) {
            if (failRead > 0) {
                failRead--;
                throw new MongoException("read failed");
            }
            return super.findUncached(collection, key, docReadPref);
        }
View Full Code Here

    }
    WriteResult result = collection.update(
      criteria, toModifierObject(),
      upsert, multi, concern, dbEncoder);
    if (result.getError()!=null) {
      throw new MongoException(result.getError());
    }
    return result;
  }
View Full Code Here

  @Test
  public void mongoIsDown() throws Exception {
    MongoTemplate mongoTemplate = mock(MongoTemplate.class);
    given(mongoTemplate.executeCommand("{ buildInfo: 1 }")).willThrow(
        new MongoException("Connection failed"));
    MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate);

    Health health = healthIndicator.health();
    assertEquals(Status.DOWN, health.getStatus());
    assertTrue(((String) health.getDetails().get("error"))
View Full Code Here

            throw new RuntimeException( "no gridfs!" );
       
        DBObject chunk = _fs._chunkCollection.findOne( BasicDBObjectBuilder.start( "files_id" , _id )
                                                       .add( "n" , i ).get() );
        if ( chunk == null )
            throw new MongoException( "can't find a chunk!  file id: " + _id + " chunk: " + i );

        return (byte[])chunk.get( "data" );
    }
View Full Code Here

     * @param chunkSize Size of chunks for file in bytes.
     * @throws MongoException if there's a problem saving the file.
     */
    public void save( long chunkSize ) {
        if (_outputStream != null)
            throw new MongoException( "cannot mix OutputStream and regular save()" );

        // note that chunkSize only changes _chunkSize in case we actually save chunks
        // otherwise there is a risk file and chunks are not compatible
        if ( ! _savedChunks ) {
            try {
                saveChunks( chunkSize );
            } catch ( IOException ioe ) {
                throw new MongoException( "couldn't save chunks" , ioe );
            }
        }

        super.save();
    }
View Full Code Here

     * @throws IOException    on problems reading the new entry's {@link java.io.InputStream}.
     * @throws MongoException
     */
    public int saveChunks( long chunkSize ) throws IOException {
        if (_outputStream != null)
            throw new MongoException( "cannot mix OutputStream and regular save()" );
        if ( _savedChunks )
            throw new MongoException( "chunks already saved!" );

        if ( chunkSize <= 0) {
            throw new MongoException("chunkSize must be greater than zero");
        }

        if ( _chunkSize != chunkSize ) {
            _chunkSize = chunkSize;
            _buffer = new byte[(int) _chunkSize];
View Full Code Here

TOP

Related Classes of com.mongodb.MongoException$CursorNotFound

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.