예제 #1
0
 void t() {
     for( int i = 0; i < 20; i++ ) {
         sleepmillis(21);
         string fn = "/tmp/t1";
         MongoMMF f;
         unsigned long long len = 1 * 1024 * 1024;
         assert( f.create(fn, len, /*sequential*/rand()%2==0) );
         {
             char *p = (char *) f.getView();
             assert(p);
             // write something to the private view as a test
             strcpy(p, "hello");
         }
         if( cmdLine.dur ) {
             char *w = (char *) f.view_write();
             strcpy(w + 6, "world");
         }
         MongoFileFinder ff;
         ASSERT( ff.findByPath(fn) );
     }
 }
예제 #2
0
파일: mmaptests.cpp 프로젝트: 3rf/mongo
        void run() {

            try { boost::filesystem::remove(fn); }
            catch(...) { }

            MMAPV1LockerImpl lockState;
            Lock::GlobalWrite lk(&lockState);

            {
                DurableMappedFile f;
                unsigned long long len = 256 * 1024 * 1024;
                verify( f.create(fn, len, /*sequential*/false) );
                {
                    char *p = (char *) f.getView();
                    verify(p);
                    // write something to the private view as a test
                    if (storageGlobalParams.dur)
                        privateViews.makeWritable(p, 6);
                    strcpy(p, "hello");
                }
                if (storageGlobalParams.dur) {
                    char *w = (char *) f.view_write();
                    strcpy(w + 6, "world");
                }
                MongoFileFinder ff;
                ASSERT( ff.findByPath(fn) );
                ASSERT( ff.findByPath("asdf") == 0 );
            }
            {
                MongoFileFinder ff;
                ASSERT( ff.findByPath(fn) == 0 );
            }

            int N = 10000;
#if !defined(_WIN32) && !defined(__linux__)
            // seems this test is slow on OS X.
            N = 100;
#endif

            // we make a lot here -- if we were leaking, presumably it would fail doing this many.
            Timer t;
            for( int i = 0; i < N; i++ ) {
                DurableMappedFile f;
                verify( f.open(fn, i%4==1) );
                {
                    char *p = (char *) f.getView();
                    verify(p);
                    if (storageGlobalParams.dur)
                        privateViews.makeWritable(p, 4);
                    strcpy(p, "zzz");
                }
                if (storageGlobalParams.dur) {
                    char *w = (char *) f.view_write();
                    if( i % 2 == 0 )
                        ++(*w);
                    verify( w[6] == 'w' );
                }
            }
            if( t.millis() > 10000 ) {
                mongo::unittest::log() << "warning: MMap LeakTest is unusually slow N:" << N <<
                    ' ' << t.millis() << "ms" << endl;
            }

        }
예제 #3
0
        void run() {

            try { boost::filesystem::remove(fn); }
            catch(...) { }

            writelock lk;

            {
                MongoMMF f;
                unsigned long long len = 256 * 1024 * 1024;
                assert( f.create(fn, len, /*sequential*/false) );
                {
                    char *p = (char *) f.getView();
                    assert(p);
                    // write something to the private view as a test
                    if( cmdLine.dur ) 
                        MemoryMappedFile::makeWritable(p, 6);
                    strcpy(p, "hello");
                }
                if( cmdLine.dur ) {
                    char *w = (char *) f.view_write();
                    strcpy(w + 6, "world");
                }
                MongoFileFinder ff;
                ASSERT( ff.findByPath(fn) );
                ASSERT( ff.findByPath("asdf") == 0 );
            }
            {
                MongoFileFinder ff;
                ASSERT( ff.findByPath(fn) == 0 );
            }

            int N = 10000;
#if !defined(_WIN32) && !defined(__linux__)
            // seems this test is slow on OS X.
            N = 100;
#endif

            // we make a lot here -- if we were leaking, presumably it would fail doing this many.
            Timer t;
            for( int i = 0; i < N; i++ ) {
                MongoMMF f;
                assert( f.open(fn, i%4==1) );
                {
                    char *p = (char *) f.getView();
                    assert(p);
                    if( cmdLine.dur ) 
                        MemoryMappedFile::makeWritable(p, 4);
                    strcpy(p, "zzz");
                }
                if( cmdLine.dur ) {
                    char *w = (char *) f.view_write();
                    if( i % 2 == 0 )
                        ++(*w);
                    assert( w[6] == 'w' );
                }
            }
            if( t.millis() > 10000 ) {
                log() << "warning: MMap LeakTest is unusually slow N:" << N << ' ' << t.millis() << "ms" << endl;
            }

        }