Mocha is a unittest framework for Node. In this document, we explain how you can test your javascript code and also your HTTP servers.
Use npm
to install Mocha:
npm install mocha
const ( | |
// Dictionary names. | |
active = "active" | |
dequed = "dequed" | |
) | |
func (h EnQHandler) Rcv(msg beehive.Msg, ctx beehive.RcvContext) error { | |
// TODO: assign a unique ID. | |
enq := msg.Data().(Enque) |
import ( | |
"github.com/kandoo/beehive" | |
) | |
// EnQHandler handles Enque messages. | |
type EnQHandler struct{} | |
func (h EnQHandler) Rcv(msg beehive.Msg, ctx beehive.RcvContext) error {...} | |
func (h EnQHandler) Map(msg beehive.Msg, ctx beehive.MapContext) beehive.MappedCells {...} |
// TaskRing is an efficient, gob-compatible ring buffer for Tasks. | |
// TaskRing always wastes one element. | |
type TaskRing struct { | |
... | |
Stats Stats | |
} | |
// Stats represents the statistics of the task ring buffer. | |
type Stats struct { | |
Deque uint64 // Deque represents the total nubmer of dequeued tasks. |
// Enqueue enqueus a task. | |
type Enque struct { | |
Task // The task to be enqueued. | |
} | |
// Deque represents a message emitted to dequeue a task from a queue. | |
type Deque struct { | |
Queue // The queue to dequeue a task from. | |
} |
// Queue represents a named queue. | |
type Queue string | |
// Task represents a task in a queue. | |
type Task struct { | |
ID uint64 `json:"id"` // Task's globally unique ID assigned by taskq. | |
Queue Queue `json:"queue"` // Task's queue. | |
Body []byte `json:"body"` // Task's client data. | |
} |
Mocha is a unittest framework for Node. In this document, we explain how you can test your javascript code and also your HTTP servers.
Use npm
to install Mocha:
npm install mocha
node.js
and npm
installed on your machine.bash
or zsh
as your shell.npm
installs packages locally as you don't have root permissions. To do so, you can edit ~/.npmrc
and add the following line:
prefix=$NODE_HOME
$NODE_HOME
is the directory in which you have installed node.js
.When hosting our web applications, we often have one public IP
address (i.e., an IP address visible to the outside world)
using which we want to host multiple web apps. For example, one
may wants to host three different web apps respectively for
example1.com
, example2.com
, and example1.com/images
on
the same machine using a single IP address.
How can we do that? Well, the good news is Internet browsers
var http = require('http'); | |
var hello = function(req, res) { | |
res.writeHead(200, {'Content-Type': 'text/html'}); | |
res.write('Hello! <br />'); | |
res.write('<br />' + | |
'URL:' + req.url + '<br />' + | |
'Method:' + req.method + '<br />'); | |
}; |
class RoutingService[REQUEST <: Request, RESPONSE]( | |
val routes: PartialFunction[Request, Service[REQUEST, RESPONSE]]) | |
extends Service[REQUEST, RESPONSE] { | |
protected[this] val requestToService = routes | |
def apply(request: REQUEST): Future[RESPONSE] = { | |
val service = requestToService(request) | |
service(request) | |
} |