'use strict';

var TChannel = require('tchannel');
var DebugLogtron = require('debug-logtron');

var AutobahnClient = require('../');

var allocCluster = require('autobahn/test/lib/test-cluster.js');

allocCluster.test('can register', {
    size: 5
}, function t(cluster, assert) {
    var tchannel = new TChannel();

    tchannel.listen(0, '127.0.0.1', function listening() {
        var client = new AutobahnClient({
            serviceName: 'hello-bob',
            callerName: 'hello-bob-test',
            hostPortList: cluster.hostPortList,
            tchannel: tchannel,
            logger: DebugLogtron('autobahnClient')
        });

        client.once('registered', onResponse);
        client.register();

        function onResponse() {
            var result = client.latestRegistrationResult;

            cluster.checkExitPeers(assert, {
                serviceName: 'hello-bob',
                hostPort: tchannel.hostPort
            });

            assert.equal(result.head, null);

            // Because of duplicates in a size 5 cluster we know
            // that we have at most 5 kValues
            assert.ok(result.body.connectionCount <= 5,
                'expect to have at most 5 register results');

            tchannel.close();
            client.destroy();
            assert.end();
        }
    });
});

@@ -12,44 +12,8 @@
 ';%0A%0A
-var TChannel = require('tchannel');%0A
 var 
@@ -58,20 +58,21 @@
 );%0A%0Avar 
-Auto
+Hyper
 bahnClie
@@ -92,22 +92,46 @@
 '../
+../hyperbahn/index.js
 ');%0A
-%0A
 var 
-alloc
+Hyperbahn
 Clus
@@ -149,30 +149,24 @@
 re('
-autobahn/test/lib/test
+../lib/hyperbahn
 -clu
@@ -181,13 +181,17 @@
 );%0A%0A
-alloc
+Hyperbahn
 Clus
@@ -274,99 +274,36 @@
 var 
-tchannel = new TChannel();%0A%0A    tchannel.listen(0, '127.0.0.1', function listening() %7B%0A    
+bob = cluster.remotes.bob;%0A%0A
     
@@ -323,12 +323,13 @@
 new 
-Auto
+Hyper
 bahn
@@ -337,20 +337,16 @@
 lient(%7B%0A
-    
         
@@ -379,20 +379,16 @@
         
-    
 callerNa
@@ -409,20 +409,16 @@
 -test',%0A
-    
         
@@ -453,36 +453,32 @@
 rtList,%0A        
-   
- 
 tchannel: tchann
@@ -471,17 +471,20 @@
 hannel: 
-t
+bob.
 channel,
@@ -484,20 +484,16 @@
 hannel,%0A
-    
         
@@ -531,37 +531,29 @@
 lient')%0A    
- 
-   
 %7D);%0A%0A
-    
     client.o
@@ -583,20 +583,16 @@
 ponse);%0A
-    
     clie
@@ -603,28 +603,24 @@
 egister();%0A%0A
-    
     function
@@ -635,20 +635,16 @@
 nse() %7B%0A
-    
         
@@ -698,20 +698,16 @@
         
-   
- 
 cluster.
@@ -739,28 +739,24 @@
             
-    
 serviceName:
@@ -777,28 +777,24 @@
             
- 
-   
 hostPort: tc
@@ -791,17 +791,20 @@
 stPort: 
-t
+bob.
 channel.
@@ -820,29 +820,21 @@
         
-    
 %7D);%0A%0A
-    
         
@@ -875,20 +875,16 @@
         
-    
 // Becau
@@ -936,20 +936,16 @@
         
-    
 // that 
@@ -974,28 +974,24 @@
 ues%0A        
-   
- 
 assert.ok(re
@@ -1022,20 +1022,16 @@
 t %3C= 5,%0A
-    
         
@@ -1085,42 +1085,8 @@
 );%0A%0A
-            tchannel.close();%0A    
     
@@ -1111,28 +1111,24 @@
 ();%0A        
-    
 assert.end()
@@ -1137,21 +1137,9 @@
     
- 
-   %7D%0A    %7D);
+%7D
 %0A%7D);

make register test work