env.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright 2015 rain1017.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  12. // implied. See the License for the specific language governing
  13. // permissions and limitations under the License. See the AUTHORS file
  14. // for names of contributors.
  15. 'use strict';
  16. var should = require('should');
  17. var path = require('path');
  18. var child_process = require('child_process');
  19. var quick = require('quick-pomelo');
  20. var P = quick.Promise;
  21. var logger = quick.logger.getLogger('test', __filename);
  22. P.longStackTraces();
  23. var execMemdbClusterSync = function(cmd){
  24. var configPath = path.join(__dirname, 'memdb.conf.js');
  25. var output = child_process.execFileSync('memdbcluster', [cmd, '--conf=' + configPath]);
  26. logger.info(output.toString());
  27. };
  28. exports.initMemdbSync = function(){
  29. execMemdbClusterSync('drop');
  30. execMemdbClusterSync('start');
  31. };
  32. exports.closeMemdbSync = function(){
  33. execMemdbClusterSync('stop');
  34. };
  35. exports.memdbConfig = {
  36. backend : {
  37. engine : 'mongodb',
  38. url : 'mongodb://localhost/quick-pomelo-test',
  39. options : {},
  40. },
  41. shards : {
  42. 'player-server-1' : {
  43. host : '127.0.0.1',
  44. port : 32017,
  45. },
  46. 'area-server-1' : {
  47. host : '127.0.0.1',
  48. port : 32017,
  49. },
  50. 'team-server-1' : {
  51. host : '127.0.0.1',
  52. port : 32017,
  53. },
  54. },
  55. };
  56. exports.createApp = function(serverId, serverType){
  57. var app = quick.mocks.app({serverId : serverId, serverType : serverType});
  58. app.setBase(path.join(__dirname, '..'));
  59. app.set('memdbConfig', exports.memdbConfig);
  60. app.load(quick.components.memdb);
  61. app.load(quick.components.controllers);
  62. return app;
  63. };