<commit_before>require 'spec_helper'
require 'torquebox-messaging'

describe "messaging rack test" do

  deploy <<-END.gsub(/^ {4}/,'')
    ---
    application:
      root: #{File.dirname(__FILE__)}/../apps/rack/messaging
    web:
      context: /messaging-rack
    
    ruby:
      version: #{RUBY_VERSION[0,3]}
  END

  it "should receive a ham biscuit" do
    visit "/messaging-rack/?ham-biscuit"
    result = TorqueBox::Messaging::Queue.new('/queues/results').receive(:timeout => 30_000)
    result.should == "TestQueueConsumer=ham-biscuit"
  end

  it "should receive a topic ham biscuit" do
    receive_thread = Thread.new {
      result = TorqueBox::Messaging::Topic.new('/topics/test').receive(:timeout => 30_000)
      result.should == "topic-ham-biscuit"
      result = TorqueBox::Messaging::Queue.new('/queues/results').receive(:timeout => 30_000)
      result.should == "TestTopicConsumer=topic-ham-biscuit"
    }
    sleep(0.3) # ensure thread is blocking on receive from topic
    visit "/messaging-rack/?topic-ham-biscuit"
    receive_thread.join
  end

end


remote_describe "in-container messaging tests" do

  describe "message enumeration" do
    it "should allow enumeration of the messages" do
      queue = TorqueBox::Messaging::Queue.start "/queues/browseable"
      queue.publish "howdy"
      queue.first.decode.should == 'howdy'
      queue.stop
    end

    it "should accept a selector" do
      queue = TorqueBox::Messaging::Queue.start "/queues/browseable"
      queue.enumerable_options = { :selector => 'blurple > 5' }
      queue.publish "howdy", :properties => {:blurple => 5}
      queue.publish "ahoyhoy", :properties => {:blurple => 6}
      queue.first.decode.should == 'ahoyhoy'
      queue.detect { |m| m.decode == 'howdy' }.should be_nil
      queue.detect { |m| m.decode == 'ahoyhoy' }.should_not be_nil
      queue.stop
    end
  end
<commit_msg>Making sure Queue#count works like I thought.<commit_after>require 'spec_helper'
require 'torquebox-messaging'

describe "messaging rack test" do

  deploy <<-END.gsub(/^ {4}/,'')
    ---
    application:
      root: #{File.dirname(__FILE__)}/../apps/rack/messaging
    web:
      context: /messaging-rack
    
    ruby:
      version: #{RUBY_VERSION[0,3]}
  END

  it "should receive a ham biscuit" do
    visit "/messaging-rack/?ham-biscuit"
    result = TorqueBox::Messaging::Queue.new('/queues/results').receive(:timeout => 30_000)
    result.should == "TestQueueConsumer=ham-biscuit"
  end

  it "should receive a topic ham biscuit" do
    receive_thread = Thread.new {
      result = TorqueBox::Messaging::Topic.new('/topics/test').receive(:timeout => 30_000)
      result.should == "topic-ham-biscuit"
      result = TorqueBox::Messaging::Queue.new('/queues/results').receive(:timeout => 30_000)
      result.should == "TestTopicConsumer=topic-ham-biscuit"
    }
    sleep(0.3) # ensure thread is blocking on receive from topic
    visit "/messaging-rack/?topic-ham-biscuit"
    receive_thread.join
  end

end


remote_describe "in-container messaging tests" do

  describe "message enumeration" do
    it "should allow enumeration of the messages" do
      queue = TorqueBox::Messaging::Queue.start "/queues/browseable"
      queue.count.should == 0
      queue.publish "howdy"
      queue.first.decode.should == 'howdy'
      queue.count.should == 1
      TorqueBox::Messaging::Queue.new("/queues/browseable").count.should == 1
      queue.stop
    end

    it "should accept a selector" do
      queue = TorqueBox::Messaging::Queue.start "/queues/browseable"
      queue.enumerable_options = { :selector => 'blurple > 5' }
      queue.publish "howdy", :properties => {:blurple => 5}
      queue.publish "ahoyhoy", :properties => {:blurple => 6}
      queue.first.decode.should == 'ahoyhoy'
      queue.detect { |m| m.decode == 'howdy' }.should be_nil
      queue.detect { |m| m.decode == 'ahoyhoy' }.should_not be_nil
      queue.stop
    end
  end

{'fraction_non_alphanumeric': 0.13855116514690982, 'fraction_numerical': 0.012411347517730497, 'mean_word_length': 3.1832627118644066, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, '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': '6527302', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1262, 'n_words': 286}