text:
package org.elasticsearch.search.fetch;

import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.RestRequest;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * Context used to fetch the {@code stored_fields}.
 */
public class StoredFieldsContext implements Writeable {
    public static final String _NONE_ = "_none_";

    private final List<String> fieldNames;
    private boolean fetchFields;

    private StoredFieldsContext(boolean fetchFields) {
        this.fetchFields = fetchFields;
        this.fieldNames = null;
    }

    private StoredFieldsContext(List<String> fieldNames) {
        Objects.requireNonNull(fieldNames, "fieldNames must not be null");
        this.fetchFields = true;
        this.fieldNames = new ArrayList<>(fieldNames);
    }

    public StoredFieldsContext(StoredFieldsContext other) {
        this.fetchFields = other.fetchFields();
        if (other.fieldNames() != null) {
            this.fieldNames = new ArrayList<>(other.fieldNames());
        } else {
            this.fieldNames = null;
        }
    }

    public StoredFieldsContext(StreamInput in) throws IOException {
        this.fetchFields = in.readBoolean();
        if (fetchFields) {
            this.fieldNames = (List<String>) in.readGenericValue();
        } else {
            this.fieldNames = null;
        }
    }

    @Override
    public void writeTo(StreamOutput out) throws IOException {
        out.writeBoolean(fetchFields);
        if (fetchFields) {
            out.writeGenericValue(fieldNames);
        }
    }

    /**
     * Gets the field names to load and return as part of the search request.
     */
    public List<String> fieldNames() {
        return fieldNames;
    }

    /**
     * Adds the field names {@code fieldNames} to the list of fields to load.
     */
    public StoredFieldsContext addFieldNames(List<String> fieldNames) {
        if (fetchFields == false || fieldNames.contains(_NONE_)) {
            throw new IllegalArgumentException("cannot combine _none_ with other fields");
        }
        this.fieldNames.addAll(fieldNames);
        return this;
    }

    /**
     * Adds a field name {@code field} to the list of fields to load.
     */
    public StoredFieldsContext addFieldName(String field) {
        if (fetchFields == false || _NONE_.equals(field)) {
            throw new IllegalArgumentException("cannot combine _none_ with other fields");
        }
        this.fieldNames.add(field);
        return this;
    }

    /**
     * Returns true if the stored fields should be fetched, false otherwise.
     */
    public boolean fetchFields() {
        return fetchFields;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        StoredFieldsContext that = (StoredFieldsContext) o;

        if (fetchFields != that.fetchFields) return false;
        return fieldNames != null ? fieldNames.equals(that.fieldNames) : that.fieldNames == null;

    }

    @Override
    public int hashCode() {
        int result = fieldNames != null ? fieldNames.hashCode() : 0;
        result = 31 * result + (fetchFields ? 1 : 0);
        return result;
    }

    public void toXContent(String preferredName, XContentBuilder builder) throws IOException {
        if (fetchFields == false) {
            builder.field(preferredName, _NONE_);
        }
        if (fieldNames != null) {
            if (fieldNames.size() == 1) {
                builder.field(preferredName, fieldNames.get(0));
            } else {
                builder.startArray(preferredName);
                for (String fieldName : fieldNames) {
                    builder.value(fieldName);
                }
                builder.endArray();
            }
        }
    }

    public static StoredFieldsContext fromList(List<String> fieldNames) {
        if (fieldNames.size() == 1 && _NONE_.equals(fieldNames.get(0))) {
            return new StoredFieldsContext(false);
        }
        if (fieldNames.contains(_NONE_)) {
            throw new IllegalArgumentException("cannot combine _none_ with other fields");
        }
        return new StoredFieldsContext(fieldNames);
    }

    public static StoredFieldsContext fromXContent(String fieldName, XContentParser parser) throws IOException {
        XContentParser.Token token = parser.currentToken();

        if (token == XContentParser.Token.VALUE_STRING) {
            return fromList(Collections.singletonList(parser.text()));
        } else if (token == XContentParser.Token.START_ARRAY) {
            ArrayList<String> list = new ArrayList<>();
            while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
                list.add(parser.text());
            }
            return fromList(list);
        } else {
            throw new ParsingException(parser.getTokenLocation(),
                "Expected [" + XContentParser.Token.VALUE_STRING + "] or ["
                    + XContentParser.Token.START_ARRAY + "] in [" + fieldName + "] but found [" + token + "]",
                parser.getTokenLocation());
        }
    }

    public static StoredFieldsContext fromRestRequest(String name, RestRequest request) {
        String sField = request.param(name);
        if (sField != null) {
            String[] sFields = Strings.splitStringByCommaToArray(sField);
            return fromList(Arrays.asList(sFields));
        }
        return null;
    }
}

redpajama_set_name: RedPajamaGithub


text:
require File.expand_path('../../fixtures/classes', __FILE__)
require 'matrix'

describe :matrix_identity, :shared => true do
  it "returns a Matrix" do
    Matrix.send(@method, 2).should be_kind_of(Matrix)
  end

  it "returns a n x n identity matrix" do
    Matrix.send(@method, 3).should == Matrix.scalar(3, 1)
    Matrix.send(@method, 100).should == Matrix.scalar(100, 1)
  end

  describe "for a subclass of Matrix" do
    it "returns an instance of that subclass" do
      MatrixSub.send(@method, 2).should be_an_instance_of(MatrixSub)
    end
  end
end


text:
Matlab API client for [DeGiro](https://www.degiro.es)'s trading platform. Using this functions you can easily automate your orders and get information about orders, funds or products.

:warning: DeGiro could change their API at any moment.


text:
import { get } from '@ember/object';
import IntercomService from 'ember-intercom-io/services/intercom';
import cfg from '../config/environment';

export default IntercomService.extend({
  config: get(cfg, 'intercom') ?? {}
});


text:
package de.lebk.verein.storage;

import de.lebk.verein.member.Member;

import javax.xml.bind.annotation.XmlType;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.GregorianCalendar;

/**
 * @author ebrinker
 */
@XmlType(name = "lease", propOrder = {"member", "amount", "dueDate"})
public class Lease {

    private Member member;
    private int amount;
    private GregorianCalendar dueDate;

    public Lease() {
    }

    Lease(Member member, int amount, GregorianCalendar dueDate) {
        this.member = member;
        this.amount = amount;
        this.dueDate = dueDate;
    }

    public Member getMember() {
        return member;
    }

    public void setMember(Member member) {
        this.member = member;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public GregorianCalendar getDueDate() {
        return dueDate;
    }

    public void setDueDate(GregorianCalendar dueDate) {
        this.dueDate = dueDate;
    }

    @Override
    public String toString() {
        DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");

        return getMember().getFullName() + "; " + getAmount() + "; " + dateFormat.format(getDueDate().getTime());
    }
}


text:
package org.wikipedia.server.restbase;

import android.support.annotation.NonNull;

import org.wikipedia.Site;
import org.wikipedia.dataclient.retrofit.RetrofitFactory;
import org.wikipedia.settings.Prefs;

import retrofit2.Retrofit;

import java.util.Locale;

/**
 * It's good to cache the Retrofit web service since it's a memory intensive object.
 * Keep the same instance around as long as we're dealing with the same domain.
 */
public final class RbPageEndpointsCache {
    public static final RbPageEndpointsCache INSTANCE = new RbPageEndpointsCache();

    private Site site;
    private RbPageService.RbEndpoints cachedWebService;
    private Retrofit retrofit;

    public static Retrofit retrofit(@NonNull Site site) {
        String endpoint = String.format(Locale.ROOT, Prefs.getRestbaseUriFormat(), site.scheme(),
                site.authority());
        return RetrofitFactory.newInstance(site, endpoint);
    }

    private RbPageEndpointsCache() {
    }

    public Retrofit getRetrofit() {
        return retrofit;
    }

    public RbPageService.RbEndpoints getRbEndpoints(Site newSite) {
        if (!newSite.equals(site)) {
            cachedWebService = createRbService(newSite);
            site = newSite;
        }
        return cachedWebService;
    }

    public void update() {
        if (site != null) {
            cachedWebService = createRbService(site);
        }
    }

    private RbPageService.RbEndpoints createRbService(Site site) {
        retrofit = retrofit(site);
        return retrofit.create(RbPageService.RbEndpoints.class);
    }
}


text:
<?php

namespace Artistas\PagSeguro;

use Log;

class PagSeguroRecorrente extends PagSeguroClient
{

    /**
     * Define os dados do plano.
     *
     * @param array $preApproval
     *
     * @return $this
     */

    public function setPreApprovalRequest(array $preApproval){

        $preApproval = [
            'email' => $this->email,
            'token' => $this->token,
            'preApprovalName'     => $this->sanitize($preApproval, 'preApprovalName'),
            'preApprovalCharge' => $this->sanitize($preApproval, 'preApprovalCharge'),
            'preApprovalPeriod'    => $this->sanitize($preApproval, 'preApprovalPeriod'),
            'preApprovalCancelUrl'    => $this->sanitize($preApproval, 'preApprovalCancelUrl'),
            'preApprovalAmountPerPayment'    => $this->sanitize($preApproval, 'preApprovalAmountPerPayment'),
            'preApprovalMembershipFee'    => $this->sanitize($preApproval, 'preApprovalMembershipFee'),
            'preApprovalTrialPeriodDuration'    => $this->sanitize($preApproval, 'preApprovalTrialPeriodDuration'),
            'preApprovalExpirationValue'    => $this->sanitize($preApproval, 'preApprovalExpirationValue'),
            'preApprovalExpirationUnit'    => $this->sanitize($preApproval, 'preApprovalExpirationUnit'),
            'maxUses'    => $this->sanitize($preApproval, 'maxUses')
        ];

        $this->preApproval = $preApproval;

        return $this->sendTransaction($this->preApproval, $this->url['request']);
    }

    /**
     * Cria um pagamento recorrente.
     *
     * @param $dados
     *
     * @return $this
     */

    public function sendPreApproval($dados){

        $array = [
            'plan'=>$dados['plan'],
            'reference'=>$dados['reference'],
            'sender'=>[
            'name'=>$dados['senderName'],
            'email'=>$dados['senderEmail'],
            'ip'=>$dados['senderIp'],
            'hash'=>$dados['senderHash'],
            'phone'=>[
            'areaCode'=>$dados['senderPhoneArea'],
            'number'=>$dados['senderPhoneNumber'],
        ],
            'address'=>[
            'street'=>$dados['senderStreet'],
            'number'=>$dados['senderNumber'],
            'complement'=>$dados['senderComplement'],
            'district'=>$dados['senderDistrict'],
            'city'=>$dados['senderCity'],
            'state'=>$dados['senderState'],
            'country'=>$dados['senderCountry'],
            'postalCode'=>$dados['senderPostalCode'],
        ],
            'documents'=>[
            [
            'type'=>$dados['senderDocumentType'],
            'value'=>$dados['senderDocumentValue'],

        ]
        ]
        ],
            'paymentMethod'=>[
            'type'=>$dados['paymentType'],
            'creditCard'=>[
            'token'=>$dados['creditCardToken'],
            'holder'=>[
            'name'=>$dados['creditCardHolderName'],
            'birthDate'=>$dados['creditCardHolderBirthDate'],
            'documents'=>[
            [
            'type'=>$dados['creditCardHolderDocumentType'],
            'value'=>$dados['creditCardHolderDocumentValue'],
        ]
        ],
            'phone'=>[
            'areaCode'=>$dados['creditCardHolderPhoneArea'],
            'number'=>$dados['creditCardHolderPhoneNumber'],
        ],
        ]
        ]
        ]
        ];

        return $this->sendJsonTransaction($array, $this->url['pre-approval']);

    }

    public function cancelPreApproval($codePreApproval){

        Log::info($codePreApproval);

        return $this->sendTransaction([
            'email' => $this->email,
            'token' => $this->token,
        ], $this->url['cancelpreapproval'].$codePreApproval, false);

    }

}


text:
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 337775 $ -->
<refentry xml:id="ziparchive.setcompressionindex" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>ZipArchive::setCompressionIndex</refname>
  <refpurpose>Set the compression method of an entry defined by its index</refpurpose>
 </refnamediv>
 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>bool</type><methodname>ZipArchive::setCompressionIndex</methodname>
   <methodparam><type>int</type><parameter>index</parameter></methodparam>
   <methodparam><type>int</type><parameter>comp_method</parameter></methodparam>
   <methodparam choice="opt"><type>int</type><parameter>comp_flags</parameter><initializer>0</initializer></methodparam>
  </methodsynopsis>
  <para>
   Set the compression method of an entry defined by its index.
  </para>
 </refsect1>
 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>index</parameter></term>
     <listitem>
      <para>
       Index of the entry.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>comp_method</parameter></term>
     <listitem>
      <para>
       The compression method. Either
       <constant>ZipArchive::CM_DEFAULT</constant>,
       <constant>ZipArchive::CM_STORE</constant> or
       <constant>ZipArchive::CM_DEFLATE</constant>.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>comp_flags</parameter></term>
     <listitem>
      <para>
       Compression flags. Currently unused.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>
 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   &return.success;
  </para>
 </refsect1>
 <refsect1 role="examples">
  &reftitle.examples;
    <example>
     <title>Add files with different compression methods to an archive</title>
     <programlisting role="php">
<![CDATA[
<?php
$zip = new ZipArchive;
$res = $zip->open('test.zip', ZipArchive::CREATE);
if ($res === TRUE) {
    $zip->addFromString('foo', 'Some text');
    $zip->addFromString('bar', 'Some other text');
    $zip->setCompressionIndex(0, ZipArchive::CM_STORE);
    $zip->setCompressionIndex(1, ZipArchive::CM_DEFLATE);
    $zip->close();
    echo 'ok';
} else {
    echo 'failed';
}
?>
]]>
     </programlisting>
    </example>
   </refsect1>
</refentry>

<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->


text:
package net.tcs.messagehandlers;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.springframework.amqp.support.converter.MessageConverter;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.task.coordinator.message.utils.TCSConstants;

import net.tcs.core.TCSDispatcher;
import net.tcs.core.TCSRollbackDispatcher;
import net.tcs.core.TaskBoard;
import net.tcs.core.TaskKey;
import net.tcs.core.TestJobDefCreateUtils;
import net.tcs.db.JobInstanceDAO;
import net.tcs.db.TaskInstanceDAO;
import net.tcs.messages.BeginJobMessage;
import net.tcs.messages.BeginTaskMessage;
import net.tcs.messages.JobCompleteMessage;
import net.tcs.messages.JobRegistrationResponse;
import net.tcs.messages.JobSubmitRequest;
import net.tcs.messages.TaskCompleteMessage;
import net.tcs.shard.TCSShardRecoveryManager;
import net.tcs.shard.TCSShardRunner.StopNotifier;
import net.tcs.state.JobState;
import net.tcs.task.JobDefinition;

public class TCSDispatcherWithStepAndRecoveryTest extends DBAdapterTestBase {
    private TcsJobExecSubmitListener jobHandler;

    private TcsJobExecBeginListener beginJobHandler;

    private TcsTaskExecEventListener taskHandler;

    private final Map<TaskKey, BeginTaskMessage> inProgressTasks = new HashMap<>();

    private final String shardId = "shard0";

    private final String jobName0 = "testjob-0";

    private final String jobName1 = "testjob-1";

    private final String jobName2 = "testjob-2";

    private final String jobName3 = "testjob-3";

    private TCSTestProducer producer;

    private TCSDispatcher dispatcher;

    private TaskBoard taskBoard;

    private final ExecutorService executor = Executors.newCachedThreadPool();

    @Override
    @BeforeClass
    public void setup() throws ClassNotFoundException, SQLException, IOException {
        MockitoAnnotations.initMocks(this);
        super.setup();

        registerJob(TestJobDefCreateUtils.createJobDefWithStepMarking0(jobName0));
        registerJob(TestJobDefCreateUtils.createJobDefWithStepMarking1(jobName1));
        registerJob(TestJobDefCreateUtils.createJobDefWithStepMarking2(jobName2));
        registerJob(TestJobDefCreateUtils.createJobDefWithStepMarking3(jobName3));
    }

    @Override
    @AfterClass
    public void cleanup() {
        executor.shutdown();
        try {
            executor.awaitTermination(5, TimeUnit.SECONDS);
        } catch (final InterruptedException e) {
            Thread.currentThread().interrupt();
        }

        super.cleanup();
    }

    @BeforeMethod
    public void before() {
        simulateRecovery();
    }

    @AfterMethod
    public void after() {
        simulateShutdown();
        inProgressTasks.clear();
    }

    @Test
    public void testJobExecutionSuccessWithZeroParallelCount() throws IOException, InterruptedException {

        final String jobId = UUID.randomUUID().toString();
        final JobSubmitRequest req = new JobSubmitRequest(jobName0, jobId, "rmq://1.2.3.4/def/rkey", null);

        jobHandler.handleSubmitJob(req);

        final List<JobInstanceDAO> runningJobs = jobInstanceAdapter.getAllInprogressJobsForShard(shardId);
        Assert.assertEquals(runningJobs.size(), 1);
        Assert.assertEquals(runningJobs.get(0).getInstanceId(), jobId);

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t0", 0)), Arrays.asList(tk("t0", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0), tk("t3", 0)),
                Arrays.asList(tk("t3", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0)), Arrays.asList(tk("t1", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t2", 0)), Arrays.asList(tk("t2", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t4", 0)), Arrays.asList(tk("t4", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t5", 0)), Arrays.asList(tk("t5", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t6", 0)), Arrays.asList(tk("t6", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t7", 0)), Arrays.asList(tk("t7", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t8", 0), tk("t9", 0)), Arrays.asList(tk("t8", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t9", 0)), Arrays.asList(tk("t9", 0)));

        final Object msg = producer.getMessage();
        Assert.assertNotNull(msg);
        final JobCompleteMessage jobCompleteMsg = (JobCompleteMessage) msg;
        Assert.assertEquals(jobCompleteMsg.getJobName(), jobName0);
        Assert.assertEquals(jobCompleteMsg.getJobId(), jobId);

        getAndAssertJobState(jobId, JobState.COMPLETE);
    }

    @Test
    public void testJobExecutionSuccessWithNonZeroParallelCount() throws IOException, InterruptedException {

        final String jobId = UUID.randomUUID().toString();
        final JobSubmitRequest req = new JobSubmitRequest(jobName0, jobId, "rmq://1.2.3.4/def/rkey", null);
        final Map<String, String> jobContext = new HashMap<>();
        final String key = String.format(TCSConstants.STEP_PARALLEL_COUNT_KEY_FORMAT, "teststep");
        jobContext.put(key, "3");
        req.setJobContext(jobContext);

        jobHandler.handleSubmitJob(req);

        final List<JobInstanceDAO> runningJobs = jobInstanceAdapter.getAllInprogressJobsForShard(shardId);
        Assert.assertEquals(runningJobs.size(), 1);
        Assert.assertEquals(runningJobs.get(0).getInstanceId(), jobId);

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t0", 0)), Arrays.asList(tk("t0", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0), tk("t3", 0)),
                Arrays.asList(tk("t3", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0)), Arrays.asList(tk("t1", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t2", 0)), Arrays.asList(tk("t2", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t4", 0), tk("t4", 1), tk("t4", 2)),
                Arrays.asList(tk("t4", 0), tk("t4", 1), tk("t4", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t5", 0), tk("t5", 1), tk("t5", 2)),
                Arrays.asList(tk("t5", 0), tk("t5", 1), tk("t5", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t6", 0), tk("t6", 1), tk("t6", 2)),
                Arrays.asList(tk("t6", 0), tk("t6", 1), tk("t6", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t7", 0), tk("t7", 1), tk("t7", 2)),
                Arrays.asList(tk("t7", 0), tk("t7", 1), tk("t7", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t8", 0), tk("t9", 0)), Arrays.asList(tk("t8", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t9", 0)), Arrays.asList(tk("t9", 0)));

        final Object msg = producer.getMessage();
        Assert.assertNotNull(msg);
        final JobCompleteMessage jobCompleteMsg = (JobCompleteMessage) msg;
        Assert.assertEquals(jobCompleteMsg.getJobName(), jobName0);
        Assert.assertEquals(jobCompleteMsg.getJobId(), jobId);

        getAndAssertJobState(jobId, JobState.COMPLETE);
    }

    @Test
    public void testJobExecutionSuccessWithNonZeroParallelCount2() throws IOException, InterruptedException {

        final String jobId = UUID.randomUUID().toString();
        final JobSubmitRequest req = new JobSubmitRequest(jobName0, jobId, "rmq://1.2.3.4/def/rkey", null);

        jobHandler.handleSubmitJob(req);

        final List<JobInstanceDAO> runningJobs = jobInstanceAdapter.getAllInprogressJobsForShard(shardId);
        Assert.assertEquals(runningJobs.size(), 1);
        Assert.assertEquals(runningJobs.get(0).getInstanceId(), jobId);

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t0", 0)), Arrays.asList(tk("t0", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0), tk("t3", 0)),
                Arrays.asList(tk("t3", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0)), new ArrayList<TaskKey>());

        completeTaskAndInjectStepCount(tk("t1", 0), "teststep", 3);

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t2", 0)), Arrays.asList(tk("t2", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t4", 0), tk("t4", 1), tk("t4", 2)),
                Arrays.asList(tk("t4", 0), tk("t4", 1), tk("t4", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t5", 0), tk("t5", 1), tk("t5", 2)),
                Arrays.asList(tk("t5", 0), tk("t5", 1), tk("t5", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t6", 0), tk("t6", 1), tk("t6", 2)),
                Arrays.asList(tk("t6", 0), tk("t6", 1), tk("t6", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t7", 0), tk("t7", 1), tk("t7", 2)),
                Arrays.asList(tk("t7", 0), tk("t7", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t7", 1)), Arrays.asList(tk("t7", 1)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t8", 0), tk("t9", 0)), Arrays.asList(tk("t8", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t9", 0)), Arrays.asList(tk("t9", 0)));

        final Object msg = producer.getMessage();
        Assert.assertNotNull(msg);
        final JobCompleteMessage jobCompleteMsg = (JobCompleteMessage) msg;
        Assert.assertEquals(jobCompleteMsg.getJobName(), jobName0);
        Assert.assertEquals(jobCompleteMsg.getJobId(), jobId);

        getAndAssertJobState(jobId, JobState.COMPLETE);
    }

    @Test
    public void testJobExecutionSuccessWithNonZeroParallelCount3() throws IOException, InterruptedException {

        final String jobId = UUID.randomUUID().toString();
        final JobSubmitRequest req = new JobSubmitRequest(jobName1, jobId, "rmq://1.2.3.4/def/rkey", null);

        jobHandler.handleSubmitJob(req);

        final List<JobInstanceDAO> runningJobs = jobInstanceAdapter.getAllInprogressJobsForShard(shardId);
        Assert.assertEquals(runningJobs.size(), 1);
        Assert.assertEquals(runningJobs.get(0).getInstanceId(), jobId);

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t0", 0)), Arrays.asList(tk("t0", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0), tk("t3", 0)),
                Arrays.asList(tk("t2", 0)));

        completeTaskAndInjectStepCount(tk("t1", 0), "teststep", 3);

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t3", 0)), Arrays.asList(tk("t3", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t10", 0), tk("t4", 0), tk("t4", 1), tk("t4", 2)),
                Arrays.asList(tk("t10", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t4", 0), tk("t4", 1), tk("t4", 2)),
                Arrays.asList(tk("t4", 0), tk("t4", 1), tk("t4", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t5", 0), tk("t5", 1), tk("t5", 2)),
                Arrays.asList(tk("t5", 0), tk("t5", 1), tk("t5", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t6", 0), tk("t6", 1), tk("t6", 2)),
                Arrays.asList(tk("t6", 0), tk("t6", 1), tk("t6", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t7", 0), tk("t7", 1), tk("t7", 2)),
                Arrays.asList(tk("t7", 0), tk("t7", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t7", 1)), Arrays.asList(tk("t7", 1)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t8", 0), tk("t9", 0)), Arrays.asList(tk("t8", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t9", 0)), Arrays.asList(tk("t9", 0)));

        final Object msg = producer.getMessage();
        Assert.assertNotNull(msg);
        final JobCompleteMessage jobCompleteMsg = (JobCompleteMessage) msg;
        Assert.assertEquals(jobCompleteMsg.getJobName(), jobName1);
        Assert.assertEquals(jobCompleteMsg.getJobId(), jobId);

        getAndAssertJobState(jobId, JobState.COMPLETE);
    }

    @Test
    public void testJobExecutionSuccessWithNonZeroParallelCountAndOneTaskInStep()
            throws IOException, InterruptedException {

        final String jobId = UUID.randomUUID().toString();
        final JobSubmitRequest req = new JobSubmitRequest(jobName2, jobId, "rmq://1.2.3.4/def/rkey", null);
        final Map<String, String> jobContext = new HashMap<>();
        final String key = String.format(TCSConstants.STEP_PARALLEL_COUNT_KEY_FORMAT, "teststep");
        jobContext.put(key, "4");
        req.setJobContext(jobContext);

        jobHandler.handleSubmitJob(req);

        final List<JobInstanceDAO> runningJobs = jobInstanceAdapter.getAllInprogressJobsForShard(shardId);
        Assert.assertEquals(runningJobs.size(), 1);
        Assert.assertEquals(runningJobs.get(0).getInstanceId(), jobId);

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t0", 0)), Arrays.asList(tk("t0", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t1", 1), tk("t1", 2), tk("t1", 3)),
                Arrays.asList(tk("t1", 0), tk("t1", 1), tk("t1", 2), tk("t1", 3)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t2", 0)), Arrays.asList(tk("t2", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t3", 0)), Arrays.asList(tk("t3", 0)));

        final Object msg = producer.getMessage();
        Assert.assertNotNull(msg);
        final JobCompleteMessage jobCompleteMsg = (JobCompleteMessage) msg;
        Assert.assertEquals(jobCompleteMsg.getJobName(), jobName2);
        Assert.assertEquals(jobCompleteMsg.getJobId(), jobId);

        getAndAssertJobState(jobId, JobState.COMPLETE);
    }

    @Test
    public void testJobExecutionSuccessWithNonZeroParallelCountAndTwoTasksInStep()
            throws IOException, InterruptedException {

        final String jobId = UUID.randomUUID().toString();
        final JobSubmitRequest req = new JobSubmitRequest(jobName3, jobId, "rmq://1.2.3.4/def/rkey", null);
        final Map<String, String> jobContext = new HashMap<>();
        final String key = String.format(TCSConstants.STEP_PARALLEL_COUNT_KEY_FORMAT, "teststep");
        jobContext.put(key, "4");
        req.setJobContext(jobContext);

        jobHandler.handleSubmitJob(req);

        final List<JobInstanceDAO> runningJobs = jobInstanceAdapter.getAllInprogressJobsForShard(shardId);
        Assert.assertEquals(runningJobs.size(), 1);
        Assert.assertEquals(runningJobs.get(0).getInstanceId(), jobId);

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t0", 0)), Arrays.asList(tk("t0", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t1", 1), tk("t1", 2), tk("t1", 3)),
                Arrays.asList(tk("t1", 0), tk("t1", 1), tk("t1", 2), tk("t1", 3)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t2", 0), tk("t2", 1), tk("t2", 2), tk("t2", 3)),
                Arrays.asList(tk("t2", 0), tk("t2", 1), tk("t2", 2), tk("t2", 3)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t3", 0)), Arrays.asList(tk("t3", 0)));

        final Object msg = producer.getMessage();
        Assert.assertNotNull(msg);
        final JobCompleteMessage jobCompleteMsg = (JobCompleteMessage) msg;
        Assert.assertEquals(jobCompleteMsg.getJobName(), jobName3);
        Assert.assertEquals(jobCompleteMsg.getJobId(), jobId);

        getAndAssertJobState(jobId, JobState.COMPLETE);
    }

    @Test
    public void testRecoveredJobExecutionSuccessWithZeroParallelCount() throws IOException, InterruptedException {

        final String jobId = UUID.randomUUID().toString();
        final JobSubmitRequest req = new JobSubmitRequest(jobName0, jobId, "rmq://1.2.3.4/def/rkey", null);

        jobHandler.handleSubmitJob(req);

        final List<JobInstanceDAO> runningJobs = jobInstanceAdapter.getAllInprogressJobsForShard(shardId);
        Assert.assertEquals(runningJobs.size(), 1);
        Assert.assertEquals(runningJobs.get(0).getInstanceId(), jobId);

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t0", 0)), Arrays.asList(tk("t0", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0), tk("t3", 0)),
                Arrays.asList(tk("t3", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0)), Arrays.asList(tk("t1", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t2", 0)), Arrays.asList(tk("t2", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t4", 0)), new ArrayList<TaskKey>());

        simulateShutdown();

        simulateRecovery();

        startRecoveryManagerThread();

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t4", 0)), Arrays.asList(tk("t4", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t5", 0)), Arrays.asList(tk("t5", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t6", 0)), Arrays.asList(tk("t6", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t7", 0)), Arrays.asList(tk("t7", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t8", 0), tk("t9", 0)), Arrays.asList(tk("t8", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t9", 0)), Arrays.asList(tk("t9", 0)));

        final Object msg = producer.getMessage();
        Assert.assertNotNull(msg);
        final JobCompleteMessage jobCompleteMsg = (JobCompleteMessage) msg;
        Assert.assertEquals(jobCompleteMsg.getJobName(), jobName0);
        Assert.assertEquals(jobCompleteMsg.getJobId(), jobId);

        getAndAssertJobState(jobId, JobState.COMPLETE);
    }

    @Test
    public void testRecoveredJobExecutionSuccessWithNonZeroParallelCount() throws IOException, InterruptedException {

        final String jobId = UUID.randomUUID().toString();
        final JobSubmitRequest req = new JobSubmitRequest(jobName0, jobId, "rmq://1.2.3.4/def/rkey", null);
        final Map<String, String> jobContext = new HashMap<>();
        final String key = String.format(TCSConstants.STEP_PARALLEL_COUNT_KEY_FORMAT, "teststep");
        jobContext.put(key, "3");
        req.setJobContext(jobContext);

        simulateShutdown();

        jobHandler.handleSubmitJob(req);

        final List<JobInstanceDAO> runningJobs = jobInstanceAdapter.getAllInprogressJobsForShard(shardId);
        Assert.assertEquals(runningJobs.size(), 1);
        Assert.assertEquals(runningJobs.get(0).getInstanceId(), jobId);

        simulateRecovery();

        startRecoveryManagerThread();

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t0", 0)), Arrays.asList(tk("t0", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0), tk("t3", 0)),
                Arrays.asList(tk("t3", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0)), Arrays.asList(tk("t1", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t2", 0)), Arrays.asList(tk("t2", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t4", 0), tk("t4", 1), tk("t4", 2)),
                Arrays.asList(tk("t4", 0), tk("t4", 1), tk("t4", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t5", 0), tk("t5", 1), tk("t5", 2)),
                Arrays.asList(tk("t5", 0), tk("t5", 1), tk("t5", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t6", 0), tk("t6", 1), tk("t6", 2)),
                Arrays.asList(tk("t6", 0), tk("t6", 1), tk("t6", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t7", 0), tk("t7", 1), tk("t7", 2)),
                Arrays.asList(tk("t7", 0), tk("t7", 1), tk("t7", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t8", 0), tk("t9", 0)), Arrays.asList(tk("t8", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t9", 0)), Arrays.asList(tk("t9", 0)));

        final Object msg = producer.getMessage();
        Assert.assertNotNull(msg);
        final JobCompleteMessage jobCompleteMsg = (JobCompleteMessage) msg;
        Assert.assertEquals(jobCompleteMsg.getJobName(), jobName0);
        Assert.assertEquals(jobCompleteMsg.getJobId(), jobId);

        getAndAssertJobState(jobId, JobState.COMPLETE);
    }

    @Test
    public void testRecoveredJobExecutionSuccessWithNonZeroParallelCount2() throws IOException, InterruptedException {

        final String jobId = UUID.randomUUID().toString();
        final JobSubmitRequest req = new JobSubmitRequest(jobName0, jobId, "rmq://1.2.3.4/def/rkey", null);

        jobHandler.handleSubmitJob(req);

        final List<JobInstanceDAO> runningJobs = jobInstanceAdapter.getAllInprogressJobsForShard(shardId);
        Assert.assertEquals(runningJobs.size(), 1);
        Assert.assertEquals(runningJobs.get(0).getInstanceId(), jobId);

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t0", 0)), Arrays.asList(tk("t0", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0), tk("t3", 0)),
                Arrays.asList(tk("t3", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0)), new ArrayList<TaskKey>());

        completeTaskAndInjectStepCount(tk("t1", 0), "teststep", 3);

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t2", 0)), Arrays.asList(tk("t2", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t4", 0), tk("t4", 1), tk("t4", 2)),
                Arrays.asList(tk("t4", 0), tk("t4", 1), tk("t4", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t5", 0), tk("t5", 1), tk("t5", 2)),
                new ArrayList<TaskKey>());

        simulateShutdown();

        simulateRecovery();

        startRecoveryManagerThread();

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t5", 0), tk("t5", 1), tk("t5", 2)),
                Arrays.asList(tk("t5", 0), tk("t5", 1), tk("t5", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t6", 0), tk("t6", 1), tk("t6", 2)),
                Arrays.asList(tk("t6", 0), tk("t6", 1), tk("t6", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t7", 0), tk("t7", 1), tk("t7", 2)),
                Arrays.asList(tk("t7", 0), tk("t7", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t7", 1)), Arrays.asList(tk("t7", 1)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t8", 0), tk("t9", 0)), Arrays.asList(tk("t8", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t9", 0)), Arrays.asList(tk("t9", 0)));

        final Object msg = producer.getMessage();
        Assert.assertNotNull(msg);
        final JobCompleteMessage jobCompleteMsg = (JobCompleteMessage) msg;
        Assert.assertEquals(jobCompleteMsg.getJobName(), jobName0);
        Assert.assertEquals(jobCompleteMsg.getJobId(), jobId);

        getAndAssertJobState(jobId, JobState.COMPLETE);
    }

    @Test
    public void testRecoveredJobExecutionSuccessWithNonZeroParallelCount3() throws IOException, InterruptedException {

        final String jobId = UUID.randomUUID().toString();
        final JobSubmitRequest req = new JobSubmitRequest(jobName0, jobId, "rmq://1.2.3.4/def/rkey", null);

        jobHandler.handleSubmitJob(req);

        final List<JobInstanceDAO> runningJobs = jobInstanceAdapter.getAllInprogressJobsForShard(shardId);
        Assert.assertEquals(runningJobs.size(), 1);
        Assert.assertEquals(runningJobs.get(0).getInstanceId(), jobId);

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t0", 0)), Arrays.asList(tk("t0", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0), tk("t3", 0)),
                Arrays.asList(tk("t3", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0)), new ArrayList<TaskKey>());

        completeTaskAndInjectStepCount(tk("t1", 0), "teststep", 3);

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t2", 0)), Arrays.asList(tk("t2", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t4", 0), tk("t4", 1), tk("t4", 2)),
                new ArrayList<TaskKey>());

        simulateShutdown();

        simulateRecovery();

        startRecoveryManagerThread();

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t4", 0), tk("t4", 1), tk("t4", 2)),
                Arrays.asList(tk("t4", 0), tk("t4", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t4", 1), tk("t5", 0), tk("t5", 2)),
                Arrays.asList(tk("t4", 1), tk("t5", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t6", 0), tk("t5", 1), tk("t5", 2)),
                Arrays.asList(tk("t5", 1), tk("t5", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t6", 0), tk("t6", 1), tk("t6", 2)),
                Arrays.asList(tk("t6", 0), tk("t6", 1), tk("t6", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t7", 0), tk("t7", 1), tk("t7", 2)),
                Arrays.asList(tk("t7", 0), tk("t7", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t7", 1)), Arrays.asList(tk("t7", 1)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t8", 0), tk("t9", 0)), Arrays.asList(tk("t8", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t9", 0)), Arrays.asList(tk("t9", 0)));

        final Object msg = producer.getMessage();
        Assert.assertNotNull(msg);
        final JobCompleteMessage jobCompleteMsg = (JobCompleteMessage) msg;
        Assert.assertEquals(jobCompleteMsg.getJobName(), jobName0);
        Assert.assertEquals(jobCompleteMsg.getJobId(), jobId);

        getAndAssertJobState(jobId, JobState.COMPLETE);
    }

    @Test
    public void testRecoveredJobExecutionSuccessWithNonZeroParallelCount4() throws IOException, InterruptedException {

        final String jobId = UUID.randomUUID().toString();
        final JobSubmitRequest req = new JobSubmitRequest(jobName0, jobId, "rmq://1.2.3.4/def/rkey", null);

        jobHandler.handleSubmitJob(req);

        final List<JobInstanceDAO> runningJobs = jobInstanceAdapter.getAllInprogressJobsForShard(shardId);
        Assert.assertEquals(runningJobs.size(), 1);
        Assert.assertEquals(runningJobs.get(0).getInstanceId(), jobId);

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t0", 0)), Arrays.asList(tk("t0", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0), tk("t3", 0)),
                Arrays.asList(tk("t3", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t1", 0), tk("t2", 0)), new ArrayList<TaskKey>());

        completeTaskAndInjectStepCount(tk("t1", 0), "teststep", 3);

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t2", 0)), Arrays.asList(tk("t2", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t4", 0), tk("t4", 1), tk("t4", 2)),
                new ArrayList<TaskKey>());

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t4", 0), tk("t4", 1), tk("t4", 2)),
                Arrays.asList(tk("t4", 0), tk("t4", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t4", 1), tk("t5", 0), tk("t5", 2)),
                Arrays.asList(tk("t4", 1), tk("t5", 0)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t6", 0), tk("t5", 1), tk("t5", 2)),
                new ArrayList<TaskKey>());

        simulateShutdown();

        simulateRecovery();

        startRecoveryManagerThread();

        completeTasks(Arrays.asList(tk("t6", 0)));
        completeTasks(Arrays.asList(tk("t5", 1), tk("t5", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t7", 0), tk("t6", 1), tk("t6", 2)),
                Arrays.asList(tk("t6", 1), tk("t6", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t7", 0), tk("t7", 1), tk("t7", 2)),
                Arrays.asList(tk("t7", 0), tk("t7", 2)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t7", 1)), Arrays.asList(tk("t7", 1)));

        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t8", 0), tk("t9", 0)), Arrays.asList(tk("t8", 0)));
        getTasksAssertAndCompleteTasks(jobId, Arrays.asList(tk("t9", 0)), Arrays.asList(tk("t9", 0)));

        final Object msg = producer.getMessage();
        Assert.assertNotNull(msg);
        final JobCompleteMessage jobCompleteMsg = (JobCompleteMessage) msg;
        Assert.assertEquals(jobCompleteMsg.getJobName(), jobName0);
        Assert.assertEquals(jobCompleteMsg.getJobId(), jobId);

        getAndAssertJobState(jobId, JobState.COMPLETE);
    }

    private Map<TaskKey, BeginTaskMessage> getAllStartedTasks(int expectedTaskCount) {
        final Map<TaskKey, BeginTaskMessage> tasks = new HashMap<>();
        int receivedTaskCount = 0;
        while (receivedTaskCount < expectedTaskCount) {
            final Object msg = producer.getMessage();
            if (msg == null) {
                break;
            }
            final BeginTaskMessage taskMsg = (BeginTaskMessage) msg;
            tasks.put(tk(taskMsg.getTaskName(), taskMsg.getTaskParallelIndex()), taskMsg);
            receivedTaskCount++;
        }
        return tasks;
    }

    private void assertTaskDetails(Collection<BeginTaskMessage> tasks, List<TaskInstanceDAO> taskDAOs) {
        final Set<TaskKey> taskNames = new HashSet<>();
        final Set<String> taskIds = new HashSet<>();
        for (final BeginTaskMessage task : tasks) {
            taskNames.add(tk(task.getTaskName(), task.getTaskParallelIndex()));
            taskIds.add(task.getTaskId());
        }
        Assert.assertTrue(tasks.size() == taskDAOs.size());
        for (final TaskInstanceDAO taskDAO : taskDAOs) {
            Assert.assertTrue(taskNames.contains(tk(taskDAO.getName(), taskDAO.getParallelExecutionIndex())));
            Assert.assertTrue(taskIds.contains(taskDAO.getInstanceId()));
        }
    }

    private void completeTasks(List<TaskKey> taskKeys) {
        for (final TaskKey taskKey : taskKeys) {
            final BeginTaskMessage task = inProgressTasks.get(taskKey);
            final TaskCompleteMessage taskCompleteMsg = new TaskCompleteMessage(task.getTaskId(), task.getJobId(),
                    RandomStringUtils.randomAlphanumeric(128));
            taskHandler.handleTaskComplete(taskCompleteMsg);
            inProgressTasks.remove(taskKey);
        }
    }

    private void completeTaskAndInjectStepCount(TaskKey taskKey, String stepName, int parallelCount) {
        final BeginTaskMessage task = inProgressTasks.get(taskKey);
        final TaskCompleteMessage taskCompleteMsg = new TaskCompleteMessage(task.getTaskId(), task.getJobId(),
                RandomStringUtils.randomAlphanumeric(128));

        final Map<String, String> taskContextOutput = new HashMap<>();
        final String key = String.format(TCSConstants.STEP_PARALLEL_COUNT_KEY_FORMAT, stepName);
        taskContextOutput.put(key, String.valueOf(parallelCount));
        taskCompleteMsg.setTaskContextOutput(taskContextOutput);

        taskHandler.handleTaskComplete(taskCompleteMsg);
        inProgressTasks.remove(taskKey);
    }

    private void getTasksAssertAndCompleteTasks(String jobId, List<TaskKey> expectedInProgressTasks,
            List<TaskKey> tasksToComplete) {

        final Map<TaskKey, BeginTaskMessage> runningTasks = getAllStartedTasks(expectedInProgressTasks.size());
        inProgressTasks.putAll(runningTasks);
        Assert.assertTrue(inProgressTasks.keySet().containsAll(expectedInProgressTasks));

        final List<TaskInstanceDAO> inProgressTaskDAOs = taskInstanceAdapter.getAllInProgressTasksForJobId(jobId);
        assertTaskDetails(inProgressTasks.values(), inProgressTaskDAOs);

        completeTasks(tasksToComplete);
    }

    private void getAndAssertJobState(String jobId, JobState expectedState) throws InterruptedException {
        String jobState = null;
        for (int i = 0; i < 5; i++) {
            Thread.sleep(200);
            final JobInstanceDAO jobDAO = jobInstanceAdapter.getJobInstanceFromDB(jobId);
            jobState = jobDAO.getState();
            if (StringUtils.equalsIgnoreCase(jobDAO.getState(), expectedState.value())) {
                break;
            }
        }
        Assert.assertEquals(jobState, expectedState.value());
    }

    private void registerJob(JobDefinition jobDef) {
        final MessageConverter messageConverter = Mockito.mock(MessageConverter.class);
        final TCSTestProducer producer = Mockito.mock(TCSTestProducer.class);

        final TcsJobRegisterListener jobRegistrationHandler = new TcsJobRegisterListener(messageConverter, producer);

        final JobRegistrationResponse resultObj = jobRegistrationHandler.processRegisterJob(jobDef);
        Assert.assertEquals("ACK", resultObj.getStatus());
    }

    private void simulateShutdown() {
        final StopNotifier stopNotifier = new StopNotifier(1);
        dispatcher.stop(stopNotifier);
        stopNotifier.waitUntilAllDispatchersStopped();
    }

    private void simulateRecovery() {
        producer = new TCSTestProducer();

        final MessageConverter messageConverter = Mockito.mock(MessageConverter.class);
        final TCSRollbackDispatcher rollbackDispatcher = Mockito.mock(TCSRollbackDispatcher.class);

        taskBoard = new TaskBoard();

        dispatcher = new TCSDispatcher(taskBoard, producer);
        executor.submit(dispatcher);

        beginJobHandler = new TcsJobExecBeginListener(shardId, messageConverter, producer, taskBoard,
                rollbackDispatcher);

        final TcsJobExecBeginListener handler = beginJobHandler;
        jobHandler = new TcsJobExecSubmitListener(messageConverter, producer) {

            @Override
            String chooseARandomShard() {
                return shardId;
            }

            @Override
            void routeBeginJobMessage(BeginJobMessage beginJobMessage, String shardId) {
                handler.handleBeginJob(beginJobMessage);
            }
        };

        taskHandler = new TcsTaskExecEventListener(shardId, messageConverter, producer, taskBoard, rollbackDispatcher);
    }

    private void startRecoveryManagerThread() {
        final Runnable recoverThread = new Runnable() {
            @Override
            public void run() {
                final TCSShardRecoveryManager recoveryManager = new TCSShardRecoveryManager(shardId, taskBoard);
                recoveryManager.recoverShard();
                System.out.println("Shard recovered");
            }
        };

        executor.submit(recoverThread);
    }

    private static TaskKey tk(String name, int parallelIndex) {
        return new TaskKey(name, parallelIndex);
    }
}


text:
import pytz

import sublime
import sublime_plugin

try:
    from .format_date import FormatDate, UnknownTimeZoneError  # ST3
except ValueError:
    from format_date import FormatDate, UnknownTimeZoneError  # ST2

ST2 = int(sublime.version()) < 3000

if not ST2:
    basestring = str

# Global variables
fdate = FormatDate()
# Global settings object
s = None
# Print tracebacks
DEBUG = False

def status(msg, e=None):
    msg = "[InsertDate] " + msg
    sublime.status_message(msg)
    if e is not None:
        msg += "\n%s: %s" % (type(e).__name__, e)
    print(msg)

    if e and DEBUG:
        import traceback
        traceback.print_exc()

def show_timezone_quickpanel(callback, selected_item):
    global s
    show_quick_panel = sublime.active_window().show_quick_panel
    if ST2:
        show_quick_panel(pytz.all_timezones, callback)
    else:
        try:
            selected_index = pytz.all_timezones.index(selected_item)
        except ValueError:
            selected_index = 0
        show_quick_panel(pytz.all_timezones, callback,
                         selected_index=selected_index)

# I wrote this for InactivePanes, but why not just use it here as well?
# TODO write methods to change settings and flush changes.
class Settings(object):
    """Provides various helping functions for wrapping the sublime settings objects.

    `settings` should be provided as a dict of tuples and attribute names should not be one of the
    existing functions. And of course they should be valid attribute names.

    Example constructor:
    Settings(
        sublime.load_settings("Preferences.sublime-settings"),
        dict(
            attr_name_to_save_as=('settings_key_to_read_from', 'default_value'),
            attr_name_to_save_as2='settings_key_to_read_from_with_default_None',
            attr_name_and_settings_key_with_default_None=None
            #, ...
        ),
        on_settings_changed,  # optional, callback
        auto_update  # optional, bool
                     # (whether the attributes should be kept up to date; default: True)
    )

    `settings_changed` will be called when the registered settings changed, and this time for real.
    Sublime Text currently behaves weird with `add_on_change` calls and the callback is run more
    often than it should be (as in, the specified setting didn't actually change), this wrapper
    however tests if one of the values has changed and then calls the callback.
    `update()` is called before the callback.

    Methods:
        * update()
            Reads all the settings and saves them in their respective attributes.
        * has_changed()
            Returns a boolean if the currently cached settings differ.
        * get_state()
            Returns a dict with the tracked settings as keys and their values (NOT the attribute
            names). With the above example: `{"settings_key_to_read_from": 'current_value'}`.
        * get_real_state()
            Same as above but ALWAYS returns the actual current values in the settings object.
        * set_callback(callback, auto_update=True)
            Calls `callback` whenever a tracked setting's value changes. See above on why this
            behavior differs to `register`.
            If `auto_update` is true it will automatically update the attributes when the settings
            changes. This is always true when a callback is set.
        * clear_callback(clear_auto_update=False)
            Clears the callback set above and returns it in the process.
    """
    _sobj = None
    _settings = None
    _callback = None
    _auto_update = False

    def __init__(self, settings_obj, settings, callback=None, auto_update=True):
        self._sobj = settings_obj

        for k, v in settings.items():
            if v is None:
                # Use the attr name as settings key and `None` as default
                settings[k] = (k, None)
            if isinstance(v, basestring):
                # Set default to `None` if a string was supplied
                settings[k] = (v, None)
        self._settings = settings

        self.update()
        self.set_callback(callback, auto_update)

    def update(self):
        for attr, (name, def_value) in self._settings.items():
            setattr(self, attr, self._sobj.get(name, def_value))

    def _on_change(self):
        # Only trigger if relevant settings changed
        if self.has_changed():
            self.update()
            if self._callback:
                self._callback()

    def _register(self, callback):
        for name, _ in self._settings.values():
            self._sobj.add_on_change(name, callback)

    def _unregister(self):
        for name, _ in self._settings.values():
            self._sobj.clear_on_change(name)

    def has_changed(self):
        return self.get_state() != self.get_real_state()

    def get_state(self):
        return dict((name, getattr(self, attr))
                    for attr, (name, _) in self._settings.items())

    def get_real_state(self):
        return dict((name, self._sobj.get(name, def_value))
                    for name, def_value in self._settings.values())

    def set_callback(self, callback, auto_update=True):
        if callback is not None and not callable(callback):
            raise TypeError("callback must be callable")

        cb = self._callback
        self._callback = callback
        if (not cb and not self._auto_update) and (callback or auto_update):
            self._register(self._on_change)

        self._auto_update = auto_update
        return cb

    def clear_callback(self, clear_auto_update=False):
        cb = self._callback
        if cb or not self._auto_update or clear_auto_update:
            self._unregister()
        self._callback = None
        return cb

################################################################################
# The actual commands

# TODO `locale` setting to modify `%c %x %X %p` representation?
# TODO `shift` param
class InsertDateCommand(sublime_plugin.TextCommand):

    """Prints Date according to given format string."""

    def run(self, edit, format=None, tz_in=None, tz_out=None):
        if format is not None:
            if format == '' or not isinstance(format, basestring) or format.isspace():
                # Not a string, empty or only whitespaces
                return

        # Do the actual parse action
        try:
            text = fdate.parse(format, tz_in, tz_out)
        except UnknownTimeZoneError as e:
            status(str(e).strip('"'), e)
            return
        except Exception as e:
            status("Error parsing format string `%s`" % format, e)
            return

        # Don't bother replacing selections with actually nothing
        if not text or text.isspace():
            return

        # Do replacements
        for r in self.view.sel():
            # Insert when sel is empty to not select the contents
            if r.empty():
                self.view.insert(edit, r.a, text)
            else:
                self.view.replace(edit, r, text)

class InsertDatePromptCommand(sublime_plugin.TextCommand):

    """Ask for a format string, while preserving the other parameters.

    If "format" is provided, it will be pre-inserted into the prompt.
    """

    def run(self, edit, format=None, tz_in=None, tz_out=None):
        self.tz_in = tz_in
        self.tz_out = tz_out

        # Unset save_on_focus_lost so that ST doesn't save and remove trailing
        # whitespace when the input/quick panel is opened, if that option is
        # also enabled. (#26)
        self.view.settings().set('save_on_focus_lost', False)

        # Ask for the format string
        i_panel = self.view.window().show_input_panel(
            # caption
            "Date format string:",
            # initial_text
            format or fdate.default['format'],
            # on_done
            self.on_format,
            # on_change (unused)
            None,
            # on_cancel
            lambda: self.view.settings().erase('save_on_focus_lost')
        )

        # Select the default text
        i_panel.sel().clear()
        i_panel.sel().add(sublime.Region(0, i_panel.size()))

    def on_format(self, fmt):
        global s
        if fmt:
            self.format = fmt
        if self.tz_out:
            self.run_for_real()
        else:
            # Ask for an output timezone
            sublime.status_message("[InsertDate] "
                                   "Please select a timezone for the output "
                                   "(press 'esc' to use same as input)")
            show_timezone_quickpanel(self.on_tz_out, self.tz_in or s.tz_in)

    def on_tz_out(self, index):
        if index != -1:
            self.tz_out = pytz.all_timezones[index]
        self.run_for_real()

    def run_for_real(self):
        self.view.settings().erase('save_on_focus_lost')
        self.view.run_command(
            'insert_date',
            {'format': self.format, 'tz_in': self.tz_in, 'tz_out': self.tz_out}
        )

class InsertDatePanelCommand(sublime_plugin.TextCommand):

    """Shows a quick panel with configurable templates that are previewed."""

    panel_cache = []
    config_map = {}

    def run(self, edit, tz_in=None, tz_out=None):
        self.panel_cache = []
        self.config_map = {}

        if not isinstance(s.prompt_config, list):
            status("`prompt_config` setting is invalid")
            return

        configs = s.prompt_config
        if not isinstance(s.user_prompt_config, list):
            status("`user_prompt_config` setting is invalid")
        else:
            configs = configs + s.user_prompt_config

        if not configs:
            status("No configurations found to choose from")
            return

        # Generate panel cache for quick_panel
        for conf in configs:
            # Read config
            c = dict()
            c['tz_in']  = tz_in if tz_in else conf.get('tz_in')
            c['tz_out'] = tz_out if tz_out else conf.get('tz_out')
            c['format'] = conf.get('format')

            if isinstance(c['format'], basestring):
                c['format'] = c['format'].replace("$default", fdate.default['format'])

            # Do the actual parse action
            try:
                text = fdate.parse(**c)
            except UnknownTimeZoneError as e:
                status(str(e).strip('"'), e)
                return
            except Exception as e:
                status('Error parsing format string `%s`' % format, e)
                return

            self.panel_cache.append([conf['name'], text])
            self.config_map[conf['name']] = c

        # Unset save_on_focus_lost so that ST doesn't save and remove trailing
        # whitespace when the quick panel is opened, if that option is also
        # enabled. (#26)
        self.view.settings().set('save_on_focus_lost', False)
        self.view.window().show_quick_panel(self.panel_cache, self.on_done)

    def on_done(self, index):
        # Erase our settings override
        self.view.settings().erase('save_on_focus_lost')
        if index == -1:
            return

        name = self.panel_cache[index][0]
        self.view.run_command('insert_date', self.config_map[name])

class InsertDateSelectTimezone(sublime_plugin.ApplicationCommand):

    @staticmethod
    def on_select(index):
        global s
        if index == -1:
            return
        timezone = pytz.all_timezones[index]
        s._sobj.set('tz_in', timezone)
        s._sobj.erase('silence_timezone_request')
        sublime.save_settings('insert_date.sublime-settings')

    def run(self):
        global s
        show_timezone_quickpanel(self.on_select, s.tz_in)

################################################################################

def plugin_loaded():
    global s

    s = Settings(
        sublime.load_settings('insert_date.sublime-settings'),
        settings=dict(
            format=('format', '%c'),
            tz_in=('tz_in', 'local'),
            prompt_config=('prompt_config', []),
            user_prompt_config=('user_prompt_config', []),
            silence_timezone_request=None
        )
    )

    # Register on settings changes
    def on_settings_changed(initial=False):
        global fdate

        if not initial:
            status("settings changed")
        # These defaults will be used when the command's parameters are None
        fdate.set_default(s.get_state())

    on_settings_changed(True)  # Apply initial settings
    s.set_callback(on_settings_changed)

    if s.tz_in == 'local' and not s.silence_timezone_request:
        # Request user to set a timezone - later
        def request_timezone():
            if sublime.ok_cancel_dialog(
                "You should set your timezone in InsertDate's settings "
                "in order to properly use that package.\n"
                "Do you wish to do that now?"
                "\n\n"
                "Note: You can open the timezone prompt any time "
                'using the "InsertDate: Select Timezone" command.',
                "Yes"
            ):
                sublime.run_command('insert_date_select_timezone')
            else:
                s._sobj.set('silence_timezone_request', True)
                sublime.save_settings('insert_date.sublime-settings')

        sublime.set_timeout(request_timezone, 3000)

def plugin_unloaded():
    global s

    if s:
        s.clear_callback(True)

# ST2 backwards (and don't call it twice in ST3)
unload_handler = plugin_unloaded if ST2 else lambda: None

# Call manually if on ST2
if ST2:
    plugin_loaded()


text:
package org.apache.ambari.view.commons.hdfs;

import com.google.common.base.Strings;
import org.apache.ambari.view.ViewContext;
import org.apache.ambari.view.commons.exceptions.NotFoundFormattedException;
import org.apache.ambari.view.commons.exceptions.ServiceFormattedException;
import org.apache.ambari.view.utils.hdfs.DirListInfo;
import org.apache.ambari.view.utils.hdfs.DirStatus;
import org.apache.ambari.view.utils.hdfs.HdfsApi;
import org.apache.ambari.view.utils.hdfs.HdfsApiException;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.*;
import javax.ws.rs.core.*;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;

/**
 * File operations service
 */
public class FileOperationService extends HdfsService {
  private final static Logger LOG =
      LoggerFactory.getLogger(FileOperationService.class);

  private static final String FILES_VIEW_MAX_FILE_PER_PAGE = "views.files.max.files.per.page";
  private static final int DEFAULT_FILES_VIEW_MAX_FILE_PER_PAGE = 5000;

  private Integer maxFilesPerPage = DEFAULT_FILES_VIEW_MAX_FILE_PER_PAGE;

  /**
   * Constructor
   * @param context View Context instance
   */
  public FileOperationService(ViewContext context) {
    super(context);
    setMaxFilesPerPage(context);
  }

  private void setMaxFilesPerPage(ViewContext context) {
    String maxFilesPerPageProperty = context.getAmbariProperty(FILES_VIEW_MAX_FILE_PER_PAGE);
    LOG.info("maxFilesPerPageProperty = {}", maxFilesPerPageProperty);
    if(!Strings.isNullOrEmpty(maxFilesPerPageProperty)){
      try {
        maxFilesPerPage = Integer.parseInt(maxFilesPerPageProperty);
      }catch(Exception e){
        LOG.error("{} should be integer, but it is {}, using default value of {}", FILES_VIEW_MAX_FILE_PER_PAGE , maxFilesPerPageProperty, DEFAULT_FILES_VIEW_MAX_FILE_PER_PAGE);
      }
    }
  }

  /**
   * Constructor
   * @param context View Context instance
   */
  public FileOperationService(ViewContext context, Map<String, String> customProperties) {
    super(context, customProperties);
    this.setMaxFilesPerPage(context);
  }

  /**
   * List dir
   * @param path path
   * @param nameFilter : name on which filter is applied
   * @return response with dir content
   */
  @GET
  @Path("/listdir")
  @Produces(MediaType.APPLICATION_JSON)
  public Response listdir(@QueryParam("path") String path, @QueryParam("nameFilter") String nameFilter) {
    try {
      JSONObject response = new JSONObject();
      Map<String, Object> parentInfo = getApi().fileStatusToJSON(getApi().getFileStatus(path));
      DirStatus dirStatus = getApi().listdir(path, nameFilter, maxFilesPerPage);
      DirListInfo dirListInfo = dirStatus.getDirListInfo();
      parentInfo.put("originalSize", dirListInfo.getOriginalSize());
      parentInfo.put("truncated", dirListInfo.isTruncated());
      parentInfo.put("finalSize", dirListInfo.getFinalSize());
      parentInfo.put("nameFilter", dirListInfo.getNameFilter());
      response.put("files", getApi().fileStatusToJSON(dirStatus.getFileStatuses()));
      response.put("meta", parentInfo);
      return Response.ok(response).build();
    } catch (WebApplicationException ex) {
      throw ex;
    } catch (FileNotFoundException ex) {
      throw new NotFoundFormattedException(ex.getMessage(), ex);
    } catch (Exception ex) {
      throw new ServiceFormattedException(ex.getMessage(), ex);
    }
  }

  /**
   * Rename
   * @param request rename request
   * @return response with success
   */
  @POST
  @Path("/rename")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response rename(final SrcDstFileRequest request) {
    try {
      HdfsApi api = getApi();
      ResponseBuilder result;
      if (api.rename(request.src, request.dst)) {
        result = Response.ok(getApi().fileStatusToJSON(api
            .getFileStatus(request.dst)));
      } else {
        result = Response.ok(new FileOperationResult(false, "Can't move '" + request.src + "' to '" + request.dst + "'")).status(422);
      }
      return result.build();
    } catch (WebApplicationException ex) {
      throw ex;
    } catch (Exception ex) {
      throw new ServiceFormattedException(ex.getMessage(), ex);
    }
  }

  /**
   * Chmod
   * @param request chmod request
   * @return response with success
   */
  @POST
  @Path("/chmod")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response chmod(final ChmodRequest request) {
    try {
      HdfsApi api = getApi();
      ResponseBuilder result;
      if (api.chmod(request.path, request.mode)) {
        result = Response.ok(getApi().fileStatusToJSON(api
            .getFileStatus(request.path)));
      } else {
        result = Response.ok(new FileOperationResult(false, "Can't chmod '" + request.path + "'")).status(422);
      }
      return result.build();
    } catch (WebApplicationException ex) {
      throw ex;
    } catch (Exception ex) {
      throw new ServiceFormattedException(ex.getMessage(), ex);
    }
  }

  /**
   * Copy file
   * @param request source and destination request
   * @return response with success
   */
  @POST
  @Path("/move")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response move(final MultiSrcDstFileRequest request,
                       @Context HttpHeaders headers, @Context UriInfo ui) {
    try {
      HdfsApi api = getApi();
      ResponseBuilder result;
      String message = "";

      List<String> sources = request.sourcePaths;
      String destination = request.destinationPath;
      if(sources.isEmpty()) {
        result = Response.ok(new FileOperationResult(false, "Can't move 0 file/folder to '" + destination + "'")).
          status(422);
        return result.build();
      }

      int index = 0;
      for (String src : sources) {
        String fileName = getFileName(src);
        String finalDestination = getDestination(destination, fileName);
        try {
          if (api.rename(src, finalDestination)) {
            index ++;
          } else {
            message = "Failed to move '" + src + "' to '" + finalDestination + "'";
            break;
          }
        } catch (IOException exception) {
          message = exception.getMessage();
          logger.error("Failed to move '{}' to '{}'. Exception: {}", src, finalDestination,
            exception.getMessage());
          break;
        }
      }
      if (index == sources.size()) {
        result = Response.ok(new FileOperationResult(true)).status(200);
      } else {
        FileOperationResult errorResult = getFailureFileOperationResult(sources, index, message);
        result = Response.ok(errorResult).status(422);
      }
      return result.build();
    } catch (Exception ex) {
      throw new ServiceFormattedException(ex.getMessage(), ex);
    }
  }

  /**
   * Copy file
   * @param request source and destination request
   * @return response with success
   */
  @POST
  @Path("/copy")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response copy(final MultiSrcDstFileRequest request,
                       @Context HttpHeaders headers, @Context UriInfo ui) {
    try {
      HdfsApi api = getApi();
      ResponseBuilder result;
      String message = "";

      List<String> sources = request.sourcePaths;
      String destination = request.destinationPath;
      if(sources.isEmpty()) {
        result = Response.ok(new FileOperationResult(false, "Can't copy 0 file/folder to '" + destination + "'")).
          status(422);
        return result.build();
      }

      int index = 0;
      for (String src : sources) {
        String fileName = getFileName(src);
        String finalDestination = getDestination(destination, fileName);
        try {
          api.copy(src, finalDestination);
          index ++;
        } catch (IOException|HdfsApiException exception) {
          message = exception.getMessage();
          logger.error("Failed to copy '{}' to '{}'. Exception: {}", src, finalDestination,
            exception.getMessage());
          break;
        }
      }
      if (index == sources.size()) {
        result = Response.ok(new FileOperationResult(true)).status(200);
      } else {
        FileOperationResult errorResult = getFailureFileOperationResult(sources, index, message);
        result = Response.ok(errorResult).status(422);
      }
      return result.build();
    } catch (Exception ex) {
      throw new ServiceFormattedException(ex.getMessage(), ex);
    }
  }

  /**
   * Make directory
   * @param request make directory request
   * @return response with success
   */
  @PUT
  @Path("/mkdir")
  @Produces(MediaType.APPLICATION_JSON)
  public Response mkdir(final MkdirRequest request) {
    try{
      HdfsApi api = getApi();
      ResponseBuilder result;
      if (api.mkdir(request.path)) {
        result = Response.ok(getApi().fileStatusToJSON(api.getFileStatus(request.path)));
      } else {
        result = Response.ok(new FileOperationResult(false, "Can't create dir '" + request.path + "'")).status(422);
      }
      return result.build();
    } catch (WebApplicationException ex) {
      throw ex;
    } catch (Exception ex) {
      throw new ServiceFormattedException(ex.getMessage(), ex);
    }
  }

  /**
   * Empty trash
   * @return response with success
   */
  @DELETE
  @Path("/trash/emptyTrash")
  @Produces(MediaType.APPLICATION_JSON)
  public Response emptyTrash() {
    try {
      HdfsApi api = getApi();
      api.emptyTrash();
      return Response.ok(new FileOperationResult(true)).build();
    } catch (WebApplicationException ex) {
      throw ex;
    } catch (Exception ex) {
      throw new ServiceFormattedException(ex.getMessage(), ex);
    }
  }

  /**
   * Move to trash
   * @param request remove request
   * @return response with success
   */
  @POST
  @Path("/moveToTrash")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response moveToTrash(MultiRemoveRequest request) {
    try {
      ResponseBuilder result;
      HdfsApi api = getApi();
      String trash = api.getTrashDirPath();
      String message = "";

      if (request.paths.size() == 0) {
        result = Response.ok(new FileOperationResult(false, "No path entries provided.")).status(422);
      } else {
        if (!api.exists(trash)) {
          if (!api.mkdir(trash)) {
            result = Response.ok(new FileOperationResult(false, "Trash dir does not exists. Can't create dir for " +
              "trash '" + trash + "'")).status(422);
            return result.build();
          }
        }

        int index = 0;
        for (MultiRemoveRequest.PathEntry entry : request.paths) {
          String trashFilePath = api.getTrashDirPath(entry.path);
          try {
            if (api.rename(entry.path, trashFilePath)) {
              index ++;
            } else {
              message = "Failed to move '" + entry.path + "' to '" + trashFilePath + "'";
              break;
            }
          } catch (IOException exception) {
            message = exception.getMessage();
            logger.error("Failed to move '{}' to '{}'. Exception: {}", entry.path, trashFilePath,
              exception.getMessage());
            break;
          }
        }
        if (index == request.paths.size()) {
          result = Response.ok(new FileOperationResult(true)).status(200);
        } else {
          FileOperationResult errorResult = getFailureFileOperationResult(getPathsFromPathsEntries(request.paths), index, message);
          result = Response.ok(errorResult).status(422);
        }
      }
      return result.build();
    } catch (Exception ex) {
      throw new ServiceFormattedException(ex.getMessage(), ex);
    }
  }

  /**
   * Remove
   * @param request remove request
   * @return response with success
   */
  @POST
  @Path("/remove")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  public Response remove(MultiRemoveRequest request, @Context HttpHeaders headers,
                         @Context UriInfo ui) {
    try {
      HdfsApi api = getApi();
      ResponseBuilder result;
      String message = "";
      if(request.paths.size() == 0) {
        result = Response.ok(new FileOperationResult(false, "No path entries provided."));
      } else {
        int index = 0;
        for (MultiRemoveRequest.PathEntry entry : request.paths) {
          try {
            if (api.delete(entry.path, entry.recursive)) {
              index++;
            } else {
              message = "Failed to remove '" + entry.path + "'";
              break;
            }
          } catch (IOException exception) {
            message = exception.getMessage();
            logger.error("Failed to remove '{}'. Exception: {}", entry.path, exception.getMessage());
            break;
          }

        }
        if (index == request.paths.size()) {
          result = Response.ok(new FileOperationResult(true)).status(200);
        } else {
          FileOperationResult errorResult = getFailureFileOperationResult(getPathsFromPathsEntries(request.paths), index, message);
          result = Response.ok(errorResult).status(422);
        }
      }
      return result.build();
    } catch (Exception ex) {
      throw new ServiceFormattedException(ex.getMessage(), ex);
    }
  }

  private List<String> getPathsFromPathsEntries(List<MultiRemoveRequest.PathEntry> paths) {
    List<String> entries = new ArrayList<>();
    for(MultiRemoveRequest.PathEntry path: paths) {
      entries.add(path.path);
    }
    return entries;
  }

  private FileOperationResult getFailureFileOperationResult(List<String> paths, int failedIndex, String message) {
    List<String> succeeded = new ArrayList<>();
    List<String> unprocessed = new ArrayList<>();
    List<String> failed = new ArrayList<>();
    ListIterator<String> iter = paths.listIterator();
    while (iter.hasNext()) {
      int index = iter.nextIndex();
      String path = iter.next();
      if (index < failedIndex) {
        succeeded.add(path);
      } else if (index == failedIndex) {
        failed.add(path);
      } else {
        unprocessed.add(path);
      }
    }
    return new FileOperationResult(false, message, succeeded, failed, unprocessed);
  }

  private String getDestination(String baseDestination, String fileName) {
    if(baseDestination.endsWith("/")) {
      return baseDestination + fileName;
    } else {
      return baseDestination + "/" + fileName;
    }
  }

  private String getFileName(String srcPath) {
    return srcPath.substring(srcPath.lastIndexOf('/') + 1);
  }

  /**
   * Wrapper for json mapping of mkdir request
   */
  @XmlRootElement
  public static class MkdirRequest {
    @XmlElement(nillable = false, required = true)
    public String path;
  }

  /**
   * Wrapper for json mapping of chmod request
   */
  @XmlRootElement
  public static class ChmodRequest {
    @XmlElement(nillable = false, required = true)
    public String path;
    @XmlElement(nillable = false, required = true)
    public String mode;
  }

  /**
   * Wrapper for json mapping of request with
   * source and destination
   */
  @XmlRootElement
  public static class SrcDstFileRequest {
    @XmlElement(nillable = false, required = true)
    public String src;
    @XmlElement(nillable = false, required = true)
    public String dst;
  }

  /**
   * Wrapper for json mapping of request with multiple
   * source and destination
   */
  @XmlRootElement
  public static class MultiSrcDstFileRequest {
    @XmlElement(nillable = false, required = true)
    public List<String> sourcePaths = new ArrayList<>();
    @XmlElement(nillable = false, required = true)
    public String destinationPath;
  }

  /**
   * Wrapper for json mapping of remove request
   */
  @XmlRootElement
  public static class MultiRemoveRequest {
    @XmlElement(nillable = false, required = true)
    public List<PathEntry> paths = new ArrayList<>();
    public static class PathEntry {
      @XmlElement(nillable = false, required = true)
      public String path;
      public boolean recursive;
    }

  }
}


text:
require 'devs'
require 'devs/models'

require 'devstone/version'
require 'devstone/dhrystone'
require 'devstone/deterministic'
require 'devstone/stochastic'
require 'devstone/generator'

module DEVStone
  class << self
    attr_accessor :random
  end
  @random = Random.new

  def generate(formalism, opts={})
    Generator.new(opts).build(formalism)
  end
  module_function :generate

  def generate_and_simulate(formalism, opts={})
    Generator.new(opts).build(formalism).simulate
  end
  module_function :generate_and_simulate
end


text:
using NakedObjects.Xat;

namespace Dreamtec.TakeXat
{
	public class FluentTestCollection<T>
	{
		public FluentTestCollection(ITestCollection collection, T o)
		{
			Collection = collection;
			Object = o;
		}

		public ITestCollection Collection { get; set; }
		public T Object { get; set; }
	}
}


text:
<!-- Describe and explain the changes you made. -->
<!-- If applicable: add some screenshots -->

### Testing guide
<!-- Describe the steps to test the changes made -->

### Checklist
- [ ] I ran the tests with `npm run test`
- [ ] I added tests for the bug I fixed (if applicable)
- [ ] I updated the README or the DOCUMENTATION (if applicable)
- [ ] I updated the demo (if applicable)
- [ ] I verified my changes on all browsers listed below:
  - [ ] Chrome
  - [ ] Safari
  - [ ] Firefox
  - [ ] IE 10+
  - [ ] Edge
  - [ ] Opera


text:
using namespace std;

struct _MELayerData {
	vector<Motif> current, next, nextAbandon;
};

MELayer::MELayer()
	:data(nullptr)
{
}

MELayer::~MELayer()
{
	delete data;
}

bool MELayer::parse(const std::vector<std::string>& param)
{
	data = new _MELayerData();

	return true;
}

bool MELayer::isStable() const
{
	return true;
}


text:
package com.caseystella.analytics.distribution

import com.twitter.algebird.QTree
import com.twitter.algebird.QTreeSemigroup
import scala.collection.JavaConversions._

object DistributionUtils {
  def createTree(values: java.lang.Iterable[java.lang.Double] ) : QTree[Double] = {
    val semigroup = new QTreeSemigroup[Double](6);
    iterableAsScalaIterable(values).map{QTree(_)}.reduce(merge(_, _, semigroup))
  }
  def createTree(value:java.lang.Double) : QTree[Double] = {
    QTree(value)
  }

  def merge(left:QTree[Double], right:QTree[Double], semigroup :QTreeSemigroup[Double] = new QTreeSemigroup(6)) : QTree[Double] = {
    semigroup.plus(left, right)
  }
  def merge(left:QTree[Double], right:QTree[Double]) : QTree[Double] = {
    merge(left, right, new QTreeSemigroup(6))
  }
}


text:
package android.widget.touchmode;

import android.widget.layout.linear.LLOfButtons1;
import android.widget.layout.linear.LLOfButtons2;
import static android.util.TouchModeFlexibleAsserts.assertInTouchModeAfterClick;
import static android.util.TouchModeFlexibleAsserts.assertNotInTouchModeAfterKey;
import static android.util.TouchModeFlexibleAsserts.assertInTouchModeAfterTap;

import android.test.ActivityInstrumentationTestCase;
import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.MediumTest;
import android.view.KeyEvent;

/**
 * Tests that the touch mode changes from various events, and that the state
 * persists across activities.
 */
public class ChangeTouchModeTest extends ActivityInstrumentationTestCase<LLOfButtons1> {

    public ChangeTouchModeTest() {
        super("com.android.frameworks.coretests", LLOfButtons1.class);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
    }

    @MediumTest
    public void testPreconditions() throws Exception {
        assertFalse("touch mode", getActivity().isInTouchMode());
    }

    @MediumTest
    public void testTouchingScreenEntersTouchMode() throws Exception {
        assertInTouchModeAfterTap(this, getActivity().getFirstButton());
        assertTrue("touch mode", getActivity().isInTouchMode());
    }

    // TODO: reenable when more reliable
    public void DISABLE_testDpadDirectionLeavesTouchMode() throws Exception {
        assertInTouchModeAfterClick(this, getActivity().getFirstButton());
        sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT);
        assertNotInTouchModeAfterKey(this, KeyEvent.KEYCODE_DPAD_RIGHT, getActivity().getFirstButton());
        assertFalse("touch mode", getActivity().isInTouchMode());
    }

    public void TODO_touchTrackBallMovementLeavesTouchMode() throws Exception {

    }

    @MediumTest
    public void testTouchModeFalseAcrossActivites() throws Exception {

        getInstrumentation().waitForIdleSync();

        LLOfButtons2 otherActivity = null;
        try {
            otherActivity =
                    launchActivity("com.android.frameworks.coretests", LLOfButtons2.class, null);
            assertNotNull(otherActivity);
            assertFalse(otherActivity.isInTouchMode());
        } finally {
            if (otherActivity != null) {
                otherActivity.finish();
            }
        }
    }

    @LargeTest
    public void testTouchModeTrueAcrossActivites() throws Exception {
        assertInTouchModeAfterClick(this, getActivity().getFirstButton());
        LLOfButtons2 otherActivity = null;
        try {
            otherActivity =
                    launchActivity("com.android.frameworks.coretests", LLOfButtons2.class, null);
            assertNotNull(otherActivity);
            assertTrue(otherActivity.isInTouchMode());
        } finally {
            if (otherActivity != null) {
                otherActivity.finish();
            }
        }
    }

    @LargeTest
    public void testTouchModeChangedInOtherActivity() throws Exception {

        assertFalse("touch mode", getActivity().isInTouchMode());

        LLOfButtons2 otherActivity = null;
        try {
            otherActivity =
                    launchActivity("com.android.frameworks.coretests", LLOfButtons2.class, null);
            assertNotNull(otherActivity);
            assertFalse(otherActivity.isInTouchMode());
            assertInTouchModeAfterClick(this, otherActivity.getFirstButton());
            assertTrue(otherActivity.isInTouchMode());
        } finally {
            if (otherActivity != null) {
                otherActivity.finish();
            }
        }

        // need to wait for async update back to window to occur
        Thread.sleep(200);

        assertTrue("touch mode", getActivity().isInTouchMode());
    }

}


text:
package com.oliver.easy.utils;

/**
 * Created by wangdong on 16-1-5.
 */
public class Utils {
}


text:
export { DefaultDependencyResolver } from "./dependency-resolver"
export { DefaultIdentifierResolver } from "./identifier-resolver"
export { DefaultPathResolver } from "./path-resolver"
export { QualifiedName } from "./qualified-name"


text:
<?xml version="1.0"?>
<flex-config xmlns="http://www.adobe.com/2006/flex-config">
  <output>C:\workstation\codemonkey\Swift\client\flex-client\.\bin\swift-client.swc</output>
  <use-network>true</use-network>
  <target-player>10.0</target-player>
  <warnings>true</warnings>
  <benchmark>false</benchmark>
  <compiler>
    <accessible>false</accessible>
    <allow-source-path-overlap>false</allow-source-path-overlap>
    <optimize>true</optimize>
    <strict>true</strict>
    <es>false</es>
    <show-actionscript-warnings>true</show-actionscript-warnings>
    <show-binding-warnings>true</show-binding-warnings>
    <show-unused-type-selector-warnings>true</show-unused-type-selector-warnings>
    <use-resource-bundle-metadata>true</use-resource-bundle-metadata>
    <verbose-stacktraces>false</verbose-stacktraces>
    <source-path>
      <path-element>c:\workstation\codemonkey\swift\client\flex-client\src</path-element>
    </source-path>
  </compiler>
  <include-classes>
    <class>org.codemonkey.swift.requestsocketserverclient.ClientRequest</class>
    <class>org.codemonkey.swift.requestsocketserverclient.DatagramDecoder</class>
    <class>org.codemonkey.swift.requestsocketserverclient.DatagramUtil</class>
    <class>org.codemonkey.swift.requestsocketserverclient.RequestByeBye</class>
    <class>org.codemonkey.swift.requestsocketserverclient.RequestPingPong</class>
    <class>org.codemonkey.swift.requestsocketserverclient.RequestSocketClient</class>
    <class>org.codemonkey.swift.requestsocketserverclient.ResponseByeBye</class>
    <class>org.codemonkey.swift.requestsocketserverclient.ResponsePingPong</class>
    <class>org.codemonkey.swift.requestsocketserverclient.ServerResponse</class>
    <class>org.codemonkey.swift.requestsocketserverclient.UnknownRequestError</class>
    <class>org.codemonkey.swift.util.Executable</class>
    <class>org.codemonkey.swift.util.Logger</class>
    <class>org.codemonkey.swift.util.StringBuilder</class>
  </include-classes>
</flex-config>


text:
extern mod std;
use core::cmp::Eq;

fn f<T:Eq>(o: &mut Option<T>) {
    assert!(*o == option::None);
}

fn main() {
    f::<int>(&mut option::None);
    //~^ ERROR illegal borrow: creating mutable alias to static item
}


text:
@class IRCServer;

@interface IRCChannel : NSManagedObject

@property (nonatomic, retain) IRCServer *server;
@property (nonatomic, retain) NSString *name;
@property (nonatomic) BOOL autojoin;

- (NSString *) properName;

@end


text:
namespace payments {

PaymentHandlerPermissionContext::PaymentHandlerPermissionContext(
    content::BrowserContext* browser_context)
    : PermissionContextBase(browser_context,
                            ContentSettingsType::PAYMENT_HANDLER,
                            blink::mojom::PermissionsPolicyFeature::kNotFound) {
}

PaymentHandlerPermissionContext::~PaymentHandlerPermissionContext() {}

void PaymentHandlerPermissionContext::DecidePermission(
    const permissions::PermissionRequestID& id,
    const GURL& requesting_origin,
    const GURL& embedding_origin,
    bool user_gesture,
    permissions::BrowserPermissionCallback callback) {
  // The user should never be prompted to authorize payment handler.
  NOTREACHED();
}

}  // namespace payments