<commit_before>
jspec.load( "/stilts-stomp.js" );

it( "should be able to send a message", function() {
  client = Stomp.client( "ws://localhost:8675/" );

  client.connect( null, null, function(frame) {
    Assert.assertEquals( "1.1", client.version );
    
    client.send("/queues/one", {priority: 9}, "content 1");
    pause();
    
    connection = server.stompProvider.connections.get(0);
    Assert.assertEquals( 1, connection.sends.size(), 0 );
  
    send = connection.sends.get( 0 );
    message = send.message;
    Assert.assertEquals( "/queues/one", message.destination );
    Assert.assertEquals( "content 1", message.contentAsString );
    
    client.disconnect();
  } );
  
  client.waitForDisconnect();
  
} );

it( "should be able to manage subscriptions", function() {
  client = Stomp.client( "ws://localhost:8675/" );

  client.connect( null, null, function(frame) {
    connected = true;
    Assert.assertEquals( "1.1", client.version );
    
    subscription_id = client.subscribe("/queues/one", function(msg) {
    } );
    pause();
    
    connection = server.stompProvider.connections.get(0);
    Assert.assertEquals( 1, connection.subscriptions.size(), 0 );
    
    subscription = connection.subscriptions.get( subscription_id );
    Assert.assertEquals( "/queues/one", subscription.destination );
    
    client.unsubscribe( subscription_id );
    pause();
    
    Assert.assertEquals( 0, connection.subscriptions.size(), 0 );
  
    client.disconnect();
  } );
  
  client.waitForDisconnect();
} );<commit_msg>Test transaction handling in javascript client.<commit_after>
jspec.load( "/stilts-stomp.js" );

it( "should be able to send a message", function() {
  client = Stomp.client( "ws://localhost:8675/" );

  client.connect( null, null, function(frame) {
    Assert.assertEquals( "1.1", client.version );
    
    client.send("/queues/one", {priority: 9}, "content 1");
    pause();
    
    connection = server.stompProvider.connections.get(0);
    Assert.assertEquals( 1, connection.sends.size(), 0 );
  
    send = connection.sends.get( 0 );
    message = send.message;
    Assert.assertEquals( "/queues/one", message.destination );
    Assert.assertEquals( "content 1", message.contentAsString );
    
    client.disconnect();
  } );
  
  client.waitForDisconnect();
  
} );

it( "should be able to manage subscriptions", function() {
  client = Stomp.client( "ws://localhost:8675/" );

  client.connect( null, null, function(frame) {
    Assert.assertEquals( "1.1", client.version );
    
    subscription_id = client.subscribe("/queues/one", function(msg) {
    } );
    pause();
    
    connection = server.stompProvider.connections.get(0);
    Assert.assertEquals( 1, connection.subscriptions.size(), 0 );
    
    subscription = connection.subscriptions.get( subscription_id );
    Assert.assertEquals( "/queues/one", subscription.destination );
    
    client.unsubscribe( subscription_id );
    pause();
    
    Assert.assertEquals( 0, connection.subscriptions.size(), 0 );
  
    client.disconnect();
  } );
  
  client.waitForDisconnect();
} );

it( "should be able to manage transactions", function() {
  client = Stomp.client( "ws://localhost:8675/" );

  client.connect( null, null, function(frame) {
    Assert.assertEquals( "1.1", client.version );
    
    client.begin( "tx-1" );
    client.send("/queues/one", {transaction: "tx-1"}, "message in a transaction");
    
    pause();
    
    connection = server.stompProvider.connections.get(0);
    Assert.assertEquals( 1, connection.sends.size(), 0 );
  
    send = connection.sends.get( 0 );
    message = send.message;
    Assert.assertEquals( "/queues/one", message.destination );
    Assert.assertEquals( "message in a transaction", message.contentAsString );
    Assert.assertEquals( "tx-1", message.headers.get( "transaction" ) );
    
    Assert.assertEquals( 1, connection.begins.size(), 0 );
    Assert.assertEquals( "tx-1", connection.begins.get( 0 ) );
    
    Assert.assertEquals( 0, connection.commits.size(), 0 );
    
    client.commit( "tx-1" );
    pause();
    
    Assert.assertEquals( 1, connection.begins.size(), 0 );
    Assert.assertEquals( "tx-1", connection.begins.get( 0 ) );
    
    Assert.assertEquals( 1, connection.commits.size(), 0 );
    Assert.assertEquals( "tx-1", connection.commits.get( 0 ) );
    
    client.disconnect();
  } );
  
  client.waitForDisconnect();

});

it( "should be implicitly abort open transactions upon disconnect", function() {
  client = Stomp.client( "ws://localhost:8675/" );

  client.connect( null, null, function(frame) {
    Assert.assertEquals( "1.1", client.version );
    
    client.begin( "tx-1" );
    client.send("/queues/one", {transaction: "tx-1"}, "message in a transaction");
    
    pause();
    
    connection = server.stompProvider.connections.get(0);
    Assert.assertEquals( 1, connection.sends.size(), 0 );
  
    send = connection.sends.get( 0 );
    message = send.message;
    Assert.assertEquals( "/queues/one", message.destination );
    Assert.assertEquals( "message in a transaction", message.contentAsString );
    Assert.assertEquals( "tx-1", message.headers.get( "transaction" ) );
    
    Assert.assertEquals( 1, connection.begins.size(), 0 );
    Assert.assertEquals( "tx-1", connection.begins.get( 0 ) );
    
    Assert.assertEquals( 0, connection.commits.size(), 0 );
    
    client.disconnect();
    
    Assert.assertEquals( 1, connection.begins.size(), 0 );
    Assert.assertEquals( "tx-1", connection.begins.get( 0 ) );
    
    Assert.assertEquals( 0, connection.commits.size(), 0 );
    
    Assert.assertEquals( 0, connection.aborts.size(), 0 );
    Assert.assertEquals( "tx-1", connection.aborts.get( 0 ) );
  } );
  
  client.waitForDisconnect();

});
{'fraction_non_alphanumeric': 0.15982683982683982, 'fraction_numerical': 0.01818181818181818, 'mean_word_length': 3.2533136966126657, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5533095', 'n_tokens_mistral': 1831, 'n_tokens_neox': 1748, 'n_words': 362}