Permalink
Browse files

First logging messaage - startup

  • Loading branch information...
1 parent 01ab1c3 commit ef592e519db7f2757627bb63e8a192c412281a6f @christav christav committed Mar 16, 2013
Showing with 67 additions and 6 deletions.
  1. +9 −6 lib/sbstore.js
  2. +58 −0 test/logging-tests.js
View
@@ -41,8 +41,14 @@ ServiceBusStore.Client = Client;
function ServiceBusStore(options) {
io.Store.apply(this, arguments);
+ this.log = options && options.logger;
+
this.nodeId = (options && options.nodeId) || uuid.v4();
this.sb = this.createServiceBusConnector(options);
+
+ this.log && this.log.info('Service Bus Store created', 'host:' + this.serviceBusService.host,
+ 'topic:' + options.topic, 'sub:' + options.subscription);
+
this.subscribers = {};
this.hookupListeners(options && options.listeners);
@@ -118,19 +124,17 @@ ServiceBusStore.prototype.createServiceBusConnector = function createServiceBusC
throw new Error('Must specify one of connectionString or serviceBusService in options');
}
- var serviceBusService;
-
if (options.connectionString) {
- serviceBusService = azure.createServiceBusService(options.connectionString);
+ this.serviceBusService = azure.createServiceBusService(options.connectionString);
} else {
- serviceBusService = options.serviceBusService;
+ this.serviceBusService = options.serviceBusService;
}
var createOptions = {
nodeId: this.nodeId,
topic: options.topic,
subscription: options.subscription,
- serviceBusService: serviceBusService
+ serviceBusService: this.serviceBusService
};
return new MessageBatcher(createOptions,
@@ -150,4 +154,3 @@ ServiceBusStore.prototype.hookupListeners = function (listeners) {
l.sb(that.sb);
});
}
-
View
@@ -0,0 +1,58 @@
+/**
+* Copyright (c) Microsoft. All rights reserved.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+'use strict';
+
+var should = require('should');
+var sinon = require('sinon');
+
+var SbStore = require('../lib/sbstore');
+
+describe('logging', function () {
+ var store;
+ var logger;
+ var serviceBusService;
+
+ beforeEach(function () {
+ serviceBusService = {
+ receiveSubscriptionMessage: sinon.spy(),
+ sendTopicMessage: sinon.spy(),
+ withFilter: function (filter) { return this; },
+ host: 'testnamespace.servicebus.example'
+ };
+
+ logger = {
+ error: sinon.spy(),
+ warn: sinon.spy(),
+ info: sinon.spy(),
+ debug: sinon.spy()
+ };
+
+ store = new SbStore({
+ nodeId: 'logtestnode',
+ topic: 'testtopic',
+ subscription: 'testsubscription',
+ serviceBusService: serviceBusService,
+ logger: logger
+ });
+ });
+
+ it('should log subscription info on startup', function () {
+ logger.info.calledWith('Service Bus Store created',
+ 'host:' + serviceBusService.host,
+ 'topic:testtopic',
+ 'sub:testsubscription').should.be.true;
+ });
+});

0 comments on commit ef592e5

Please sign in to comment.