<commit_before>require 'test/unit'
require 'radius'

class MultithreadTest < Test::Unit::TestCase

  def setup
    Thread.abort_on_exception
    @context = Radius::Context.new do |c|
      c.define_tag('thread') do |tag|
        "#{tag.locals.thread_id} / #{tag.globals.object_id}"
      end
    end
  end

  def test_runs_multithreaded
    threads = []
    1000.times do |t|
      threads << Thread.new do
        parser = Radius::Parser.new(@context, :tag_prefix => 'r')
        parser.context.globals.thread_id = Thread.current.object_id
        expected = "#{Thread.current.object_id} / #{parser.context.globals.object_id}"
        actual = parser.parse('<r:thread />')
        assert_equal expected, actual
      end
    end
    threads.each{|t| t.join }
  end

end<commit_msg>Update multithreaded_test to detect java version.<commit_after>require 'test/unit'
require 'radius'

class MultithreadTest < Test::Unit::TestCase

  def setup
    Thread.abort_on_exception
    @context = Radius::Context.new do |c|
      c.define_tag('thread') do |tag|
        "#{tag.locals.thread_id} / #{tag.globals.object_id}"
      end
    end
  end

  if RUBY_PLATFORM == 'java'
    require 'radius/parser/jscanner'
    def test_runs_multithreaded
      lock = java.lang.String.new("lock")
      threads = []
      1000.times do |t|
        thread = Thread.new do
                   parser = Radius::Parser.new(
                              @context,
                              :tag_prefix => 'r',
                              :scanner => Radius::JScanner.new
                            )
                   parser.context.globals.thread_id = Thread.current.object_id
                   expected = "#{Thread.current.object_id} / "+
                              "#{parser.context.globals.object_id}"
                   actual = parser.parse('<r:thread />')
                   assert_equal expected, actual
                 end
        lock.synchronized do
          threads << thread
        end
      end
      lock.synchronized do
        threads.each{|t| t.join }
      end
    end
  else
    def test_runs_multithreaded
      threads = []
      mute = Mutex.new
      1000.times do |t|
        thread = Thread.new do
                   parser = Radius::Parser.new(@context, :tag_prefix => 'r')
                   parser.context.globals.thread_id = Thread.current.object_id
                   expected = "#{Thread.current.object_id} / "+
                              "#{parser.context.globals.object_id}"
                   actual = parser.parse('<r:thread />')
                   assert_equal expected, actual
                 end
        mute.synchronize do
          threads << thread
        end
      end
      mute.synchronize do
        threads.each{|t| t.join }
      end
    end
  end

end
{'fraction_non_alphanumeric': 0.1073345259391771, 'fraction_numerical': 0.004293381037567084, 'mean_word_length': 1.7093023255813953, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 10, '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': '1653138', 'n_tokens_mistral': 836, 'n_tokens_neox': 814, 'n_words': 164}