小编daf*_*rys的帖子

为什么一个空的MongoDB数据库如此之大?

当我使用该命令创建新的mongoDB数据库实例时

mongod --dbpath db
Run Code Online (Sandbox Code Playgroud)

db我在调用命令的目录中创建的文件夹在哪里.运行它并检查目录的大小后,我看到它的大小超过300MB - 当时没有数据.

这里发生了什么?

谢谢你的帮助!


编辑

感谢人们谈论预先分配的大小journal.

下面是数据库目录中的文件/文件夹列表,按顺序排序(现在数据库中有一点数据,但这里的大小可以忽略不计):

$du -ha | sort -n
4.0K    ./WiredTiger
4.0K    ./WiredTiger.lock
4.0K    ./WiredTiger.turtle
4.0K    ./WiredTigerLAS.wt
4.0K    ./mongod.lock
4.0K    ./storage.bson
8.0K    ./.DS_Store
8.0K    ./diagnostic.data/metrics.2016-06-10T11-07-50Z-00000
8.0K    ./diagnostic.data/metrics.interim
 16K    ./_mdb_catalog.wt
 16K    ./index-3-3697658674625742251.wt
 36K    ./collection-0-3697658674625742251.wt
 36K    ./index-1-3697658674625742251.wt
 36K    ./sizeStorer.wt
 44K    ./WiredTiger.wt
 60K    ./collection-2-3697658674625742251.wt
 72K    ./diagnostic.data/metrics.2016-06-10T10-19-31Z-00000
100M    ./journal/WiredTigerLog.0000000003
100M    ./journal/WiredTigerPreplog.0000000001
100M    ./journal/WiredTigerPreplog.0000000002
168K    ./diagnostic.data/metrics.2016-06-10T11-17-58Z-00000
256K    ./diagnostic.data
300M    ./journal
301M    .
Run Code Online (Sandbox Code Playgroud)

如您所见,日志目录几乎占据了所有空间.

mongodb

10
推荐指数
1
解决办法
3605
查看次数

编写angular2测试并更改模拟返回值 - 让它干?

我正在为服务编写一些测试,我正在改变模拟函数的响应来测试各种情况.目前,每次我想更改模拟的响应时,我都需要重置TestBed并再次配置测试模块,将我的新Mocks作为依赖项注入.

我觉得必须有一个DRYer方式来编写这个规范,但我无法弄明白.有没有人有任何想法?

(我知道我可以将此服务的测试编写为标准的ES6类,但是我使用Http响应模拟来自angular的东西的组件和服务得到了相同的场景.)

这是我的spec文件:

import { TestBed, inject } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable';
import { UserService, RestService } from '../index';
import { User } from '../../../models/index';


let getUserSpy = jasmine.createSpy('getUser');
let upsertUserSpy = jasmine.createSpy('upsertUser');


// NOTE that initally, the MockRestService throws errors for all responses
class MockRestService {
  getUser = getUserSpy.and.returnValue(Observable.throw('no thanks'));
  upsertUser = upsertUserSpy.and.returnValue(Observable.throw('no thanks'));
}


describe('User service - ', () => {

  let service;

  /**
   * First TestBed configuration
   */
  beforeEach(() => {
    TestBed.configureTestingModule({ …
Run Code Online (Sandbox Code Playgroud)

unit-testing jasmine angular2-testing angular

8
推荐指数
1
解决办法
3623
查看次数

Angular - 测试组件 - 从模拟返回 Promise.reject 时出错

我有一个组件单元测试,它没有按照我预期的方式处理来自模拟的承诺拒绝。

我在一个组件上有这个函数,它发送一些数据addUserToOrganisation并处理它返回的 Promise:

 public onSubmit() {
    this.saveStatus = 'Saving';
    this.user = this.prepareSaveUser();
    this._userService.addUserToOrganisation(this.user)
    .then(() => this._router.navigate(['/profile']))
    .catch(error => this.reportError(error));
  }
Run Code Online (Sandbox Code Playgroud)

在测试此组件时,我提供了一个模拟,用于UserService监视端点addUserToOrganisation并返回某种 Promise:

 mockUserService = jasmine.createSpyObj('mockUserService', ['getOrgId', 'addUserToOrganisation']);
 mockUserService.getOrgId.and.returnValue(Promise.resolve('an id'));
 mockUserService.addUserToOrganisation.and.returnValue(Promise.resolve());
Run Code Online (Sandbox Code Playgroud)

这对于快乐的路径(解决)来说效果很好 - 我可以测试它this._router.navigate()被调用等等。这是这条快乐路径的通过测试:

it('should navigate to /profile if save is successful', fakeAsync(() => {
    fixture.detectChanges();
    tick();
    fixture.detectChanges();

    component.userForm.controls['firstName'].setValue('John');
    component.userForm.controls['lastName'].setValue('Doe');
    component.userForm.controls['email'].setValue('j.d@gmail.com');
    component.onSubmit();

    tick();
    fixture.detectChanges();
    expect(mockRouter.navigate).toHaveBeenCalledWith(['/profile']);
  }));
Run Code Online (Sandbox Code Playgroud)

然而,我在测试“悲伤”路径时遇到了麻烦。我改变我的模拟以返回 a Promise.reject,尽管我有.catchin onSubmit,但我收到此错误:

Error: Uncaught (in promise): no
Run Code Online (Sandbox Code Playgroud)

所以这很令人困惑。这是我对这条悲伤之路的测试。请注意,我更改了模拟调用的响应。

it('should show Failed …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing promise angular-components angular

8
推荐指数
1
解决办法
8439
查看次数

using rewire to test node ES6 module - function not defined

EDIT : This was answered pretty quickly by someone pointing to something obvious in the rewire documentation. Note that I wrapped my modules in IIFEs because I was trying to get node to stop complaining about block scoped declarations outside of strict mode. Instead of using IIFEs (with strict mode), the easier way is just to use the --use-strict flag on your node command:

node --use-strict app.js
Run Code Online (Sandbox Code Playgroud)

that way you can use ES6 in your code as normal and they …

node.js jasmine ecmascript-6

5
推荐指数
1
解决办法
2354
查看次数