<commit_before>require 'rubygems'
require 'bud'
require 'test/unit'
require 'twophasecommit'

class Test2PC < Test::Unit::TestCase
  class Coordinator
    include Bud
    include TwoPCCoordinator

    bootstrap do
      add_participant <= [[1, 1, "localhost:54320"],
                          [2, 2, "localhost:54321"]]
    end
  end

  class Participant
    include Bud
    include TwoPCParticipant
  end

  def test_twopc
    coord = Coordinator.new(:port => 12345)
    p1 = Participant.new(:port => 54320)
    p2 = Participant.new(:port => 54321)

    coord.run_bg
    p1.run_bg
    p2.run_bg

    # Broadcast a commit request - it should succeed
    resps = coord.sync_callback(:commit_request, [[1]], :commit_response)
    5.times { coord.sync_do }
    #assert_equal([["C"]], resps)
    
    # # Pause participant 1
    # p1.sync_callback {p1.pause_participant <+ [[6,1]]}
    
    # # Broadcast a commit request - it should fail
    # resps = p1.sync_callback(:commit_request, [[7]], :commit_response)
    # assert_equal([["A"]], resps)

    # # Delete participant 1 now
    # p1.sync_callback {p1.delete_participant <+ [[8,1]]}

    # # Broadcast a commit request - it should succeed
    # resps = p1.sync_callback(:commit_request, [[9]], :commit_response)
    # assert_equal([["C"]], resps)

    # Pause a participant 2
    #p1.sync_callback {p1.pause_participant <+ [[10,2]]}
    
    # Broadcast a commit request - it should fail
    #resps = p1.sync_callback(:commit_request, [[11]], :commit_response)
    #assert_equal([["A"]], resps)

    # Resume participant 2
    #p1.sync_callback {p1.pause_participant <+ [[12,2]]}
    
    # Broadcast a commit request - it should succeed
    #resps = p1.sync_callback(:commit_request, [[13]], :commit_response)
    #assert_equal([["C"]], resps)<commit_msg>Uncommented tests - pause_participant doesn't work<commit_after>require 'rubygems'
require 'bud'
require 'test/unit'
require 'twophasecommit'

class Test2PC < Test::Unit::TestCase
  class Coordinator
    include Bud
    include TwoPCCoordinator

    bootstrap do
      add_participant <= [[1, 1, "localhost:54320"],
                          [2, 2, "localhost:54321"]]
    end
  end

  class Participant
    include Bud
    include TwoPCParticipant
  end

  def test_twopc
    coord = Coordinator.new(:port => 12345)
    p1 = Participant.new(:port => 54320)
    p2 = Participant.new(:port => 54321)

    coord.run_bg
    p1.run_bg
    p2.run_bg

    # Broadcast a commit request - it should succeed
    resps = coord.sync_callback(:commit_request, [[1]], :commit_response)
    5.times { coord.sync_do }
    assert_equal([[1, :C]], resps)
    
    # # Pause participant 1
    # p1.sync_callback {p1.pause_participant <+ [[6,1]]}
    
    # # Broadcast a commit request - it should fail
    # resps = p1.sync_callback(:commit_request, [[7]], :commit_response)
    # assert_equal([["A"]], resps)

    # # Delete participant 1 now
    # p1.sync_callback {p1.delete_participant <+ [[8,1]]}

    # # Broadcast a commit request - it should succeed
    # resps = p1.sync_callback(:commit_request, [[9]], :commit_response)
    # assert_equal([["C"]], resps)

    # Pause participant 2
    coord.sync_do {coord.pause_participant <+ [[10,2]]}
    5.times { coord.sync_do }
    
    # Broadcast a commit request - it should fail
    resps = coord.sync_callback(:commit_request, [[11]], :commit_response)
    assert_equal([[11, :A]], resps)

    # Resume participant 2
    coord.sync_do {coord.resume_participant <+ [[12,2]]}
    5.times { coord.sync_do }
    
    # Broadcast a commit request - it should succeed
    resps = coord.sync_callback(:commit_request, [[13]], :commit_response)
    assert_equal([[13, :C]], resps)
{'fraction_non_alphanumeric': 0.13202473783275073, 'fraction_numerical': 0.03683785963968809, 'mean_word_length': 3.2129105322763305, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, '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': '2842910', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1241, 'n_words': 293}