Skip to content

Instantly share code, notes, and snippets.

@mojavelinux
Created April 7, 2020 10:34
Show Gist options
  • Save mojavelinux/6c4f88523038273f6c95d37dd46931d3 to your computer and use it in GitHub Desktop.
Save mojavelinux/6c4f88523038273f6c95d37dd46931d3 to your computer and use it in GitHub Desktop.
JRuby thread safety test with Asciidoctor PDF and Rouge
require 'asciidoctor-pdf'
require 'java'
java_import 'java.util.concurrent.Callable'
java_import 'java.util.concurrent.FutureTask'
java_import 'java.util.concurrent.LinkedBlockingQueue'
java_import 'java.util.concurrent.ThreadPoolExecutor'
java_import 'java.util.concurrent.TimeUnit'
class App
include Callable
def call
Asciidoctor.convert <<~'EOS', backend: 'pdf', safe: :safe
:source-highlighter: rouge
[source,yaml]
----
runtime:
cache_dir: ./.cache/antora
site:
title: Antora Docs
url: https://docs.antora.org
start_page: antora::index.adoc
robots: allow
content:
sources:
- url: https://gitlab.com/antora/antora.git
start_path: docs
branches: v2.2.x, v2.1.x, v2.0.x
- url: https://gitlab.com/antora/antora-ui-default.git
start_path: docs
branches: master
asciidoc:
attributes:
experimental: ''
idprefix: ''
idseparator: '-'
linkattrs: ''
ui:
bundle:
url: https://gitlab.com/antora/antora-ui-default/-/jobs/artifacts/master/raw/build/ui-bundle.zip?job=bundle-stable
snapshot: true
supplemental_files: ./supplemental-ui
output:
dir: ./public
----
EOS
end
end
executor = ThreadPoolExecutor.new 8, 8, 60, TimeUnit::SECONDS, LinkedBlockingQueue.new
num_tests = 32
num_threads = 8
num_tests.times do |i|
tasks = []
num_threads.times do
task = FutureTask.new App.new
executor.execute task
tasks << task
end
tasks.each {|t| t.get }
end
executor.shutdown
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment