text:
package com.streamsets.datacollector.event.handler.remote;

import com.streamsets.datacollector.callback.CallbackInfo;
import com.streamsets.datacollector.callback.CallbackObjectType;
import com.streamsets.datacollector.config.PipelineConfiguration;
import com.streamsets.datacollector.config.RuleDefinitions;
import com.streamsets.datacollector.config.dto.ValidationStatus;
import com.streamsets.datacollector.execution.Manager;
import com.streamsets.datacollector.execution.PipelineState;
import com.streamsets.datacollector.execution.PipelineStateStore;
import com.streamsets.datacollector.execution.PipelineStatus;
import com.streamsets.datacollector.execution.PreviewOutput;
import com.streamsets.datacollector.execution.PreviewStatus;
import com.streamsets.datacollector.execution.Previewer;
import com.streamsets.datacollector.execution.RawPreview;
import com.streamsets.datacollector.execution.Runner;
import com.streamsets.datacollector.execution.Snapshot;
import com.streamsets.datacollector.execution.SnapshotInfo;
import com.streamsets.datacollector.execution.StateEventListener;
import com.streamsets.datacollector.execution.alerts.AlertInfo;
import com.streamsets.datacollector.execution.manager.PipelineManagerException;
import com.streamsets.datacollector.execution.manager.PipelineStateImpl;
import com.streamsets.datacollector.execution.manager.standalone.StandaloneAndClusterPipelineManager;
import com.streamsets.datacollector.execution.preview.common.PreviewOutputImpl;
import com.streamsets.datacollector.execution.runner.common.PipelineRunnerException;
import com.streamsets.datacollector.execution.runner.common.SampledRecord;
import com.streamsets.datacollector.json.ObjectMapperFactory;
import com.streamsets.datacollector.main.RuntimeInfo;
import com.streamsets.datacollector.restapi.bean.SourceOffsetJson;
import com.streamsets.datacollector.runner.PipelineRuntimeException;
import com.streamsets.datacollector.runner.StageOutput;
import com.streamsets.datacollector.runner.production.OffsetFileUtil;
import com.streamsets.datacollector.runner.production.SourceOffset;
import com.streamsets.datacollector.runner.production.SourceOffsetUpgrader;
import com.streamsets.datacollector.store.AclStoreTask;
import com.streamsets.datacollector.store.PipelineInfo;
import com.streamsets.datacollector.store.PipelineRevInfo;
import com.streamsets.datacollector.store.PipelineStoreException;
import com.streamsets.datacollector.store.PipelineStoreTask;
import com.streamsets.datacollector.util.Configuration;
import com.streamsets.datacollector.util.PipelineException;
import com.streamsets.datacollector.validation.Issues;
import com.streamsets.lib.security.acl.dto.Acl;
import com.streamsets.pipeline.api.Config;
import com.streamsets.pipeline.api.ExecutionMode;
import com.streamsets.pipeline.api.Record;
import com.streamsets.pipeline.api.Source;
import com.streamsets.pipeline.api.StageException;
import com.streamsets.pipeline.api.impl.ErrorMessage;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.mockito.Mockito;

import javax.ws.rs.core.MultivaluedMap;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

public class TestRemoteDataCollector {

  @Rule
  public TemporaryFolder tempFolder= new TemporaryFolder();

  private static class MockManager implements Manager {

    Map<String, Previewer> map = new HashMap<>();
    Map<String, PipelineState> stateMap = new HashMap<>();

    @Override
    public String getName() {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public void init() {
      // TODO Auto-generated method stub

    }

    @Override
    public void run() {
      // TODO Auto-generated method stub

    }

    @Override
    public void waitWhileRunning() throws InterruptedException {
      // TODO Auto-generated method stub

    }

    @Override
    public void stop() {
      // TODO Auto-generated method stub
    }

    @Override
    public Status getStatus() {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public Previewer createPreviewer(String user, String name, String rev) throws PipelineStoreException {
      Previewer previewer = new MockPreviewer(user, name, rev);
      map.put(previewer.getId(), previewer);
      return previewer;
    }

    @Override
    public Previewer getPreviewer(String previewerId) {
      return map.get(previewerId);
    }

    @Override
    public Runner getRunner(
        String name,
        String rev
    ) throws PipelineStoreException, PipelineManagerException {
      return new MockRunner();
    }

    @Override
    public List<PipelineState> getPipelines() throws PipelineStoreException {
      // Create 3 remote pipelines
      PipelineState pipelineStatus1 = new PipelineStateImpl("user",
          "ns:name",
          "rev",
          PipelineStatus.EDITED,
          null,
          System.currentTimeMillis(),
          null,
          ExecutionMode.STANDALONE,
          null,
          0,
          -1
      );
      PipelineState pipelineStatus2 = new PipelineStateImpl("user1",
          "ns:name1",
          "rev1",
          PipelineStatus.EDITED,
          null,
          System.currentTimeMillis(),
          null,
          ExecutionMode.STANDALONE,
          null,
          0,
          -1
      );
      PipelineState pipelineStatus3 = new PipelineStateImpl("user1",
          "ns:name2",
          "rev1",
          PipelineStatus.RUNNING,
          null,
          System.currentTimeMillis(),
          null,
          ExecutionMode.STANDALONE,
          null,
          0,
          -1
      );
      // create one local pipeline in active state
      PipelineState pipelineStatus4 = new PipelineStateImpl("user1",
          "local",
          "rev1",
          PipelineStatus.RUNNING,
          null,
          System.currentTimeMillis(),
          null,
          ExecutionMode.STANDALONE,
          null,
          0,
          -1
      );
      // create one local pipeline in non active state
      PipelineState pipelineStatus5 = new PipelineStateImpl("user1",
          "localError",
          "rev1",
          PipelineStatus.RUN_ERROR,
          null,
          System.currentTimeMillis(),
          null,
          ExecutionMode.STANDALONE,
          null,
          0,
          -1
      );
      List<PipelineState> pipelineList = new ArrayList<PipelineState>();
      pipelineList.add(pipelineStatus1);
      pipelineList.add(pipelineStatus2);
      pipelineList.add(pipelineStatus3);
      pipelineList.add(pipelineStatus4);
      pipelineList.add(pipelineStatus5);
      stateMap.put(pipelineStatus1.getPipelineId() + "::" + pipelineStatus1.getRev(), pipelineStatus1);
      stateMap.put(pipelineStatus2.getPipelineId() + "::" + pipelineStatus2.getRev(), pipelineStatus2);
      stateMap.put(pipelineStatus3.getPipelineId() + "::" + pipelineStatus3.getRev(), pipelineStatus3);
      stateMap.put(pipelineStatus4.getPipelineId() + "::" + pipelineStatus4.getRev(), pipelineStatus4);
      stateMap.put(pipelineStatus5.getPipelineId() + "::" + pipelineStatus5.getRev(), pipelineStatus5);
      return pipelineList;
    }

    public PipelineState getPipelineState(String name, String rev) throws PipelineStoreException {
      return stateMap.get(name + "::" + rev);
    }

    @Override
    public boolean isPipelineActive(String name, String rev) throws PipelineStoreException {
      return stateMap.get(name + "::" + rev).getStatus().isActive();
    }

    @Override
    public boolean isRemotePipeline(String name, String rev) throws PipelineStoreException {
      return (name.contains(":") ? true : false);
    }

    @Override
    public void addStateEventListener(StateEventListener listener) {
      //
    }
  }

  private static class MockRunner implements Runner {

    public static int stopCalled;

    @Override
    public String getName() {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public String getRev() {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public String getPipelineTitle() throws PipelineException {
      return null;
    }

    @Override
    public void resetOffset(String user) throws PipelineStoreException, PipelineRunnerException {
      // TODO Auto-generated method stub

    }

    @Override
    public SourceOffset getCommittedOffsets() throws PipelineException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public void updateCommittedOffsets(SourceOffset sourceOffset) throws PipelineException {
    }

    @Override
    public PipelineState getState() throws PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public void prepareForDataCollectorStart(String user) throws PipelineStoreException, PipelineRunnerException {
      // TODO Auto-generated method stub

    }

    @Override
    public void onDataCollectorStart(String user) throws PipelineException, StageException {
      // TODO Auto-generated method stub

    }

    @Override
    public void onDataCollectorStop(String user) throws PipelineStoreException, PipelineRunnerException, PipelineRuntimeException {
      // TODO Auto-generated method stub

    }

    @Override
    public void stop(String user) throws PipelineException {
      stopCalled++;
    }

    @Override
    public void forceQuit(String user) throws PipelineException {
      // No-op
    }

    @Override
    public void prepareForStart(String user) throws PipelineStoreException, PipelineRunnerException {
      // TODO Auto-generated method stub

    }

    @Override
    public void prepareForStop(String user) throws PipelineStoreException, PipelineRunnerException {
      // TODO Auto-generated method stub

    }

    @Override
    public void start(String user) throws PipelineRunnerException, PipelineStoreException, PipelineRuntimeException,
        StageException {
      // TODO Auto-generated method stub
    }

    @Override
    public void start(
        String user,
        Map<String, Object> runtimeParameters
    ) throws PipelineRunnerException, PipelineStoreException, PipelineRuntimeException,
        StageException {
      // TODO Auto-generated method stub
    }

    @Override
    public void startAndCaptureSnapshot(
        String user,
        Map<String, Object> runtimeParameters,
        String snapshotName,
        String snapshotLabel,
        int batches,
        int batchSize
    ) throws PipelineException, StageException {
      // TODO Auto-generated method stub
    }

    @Override
    public String captureSnapshot(
        String user,
        String snapshotName,
        String snapshotLabel,
        int batches,
        int batchSize
    ) throws PipelineException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public String updateSnapshotLabel(String snapshotName, String snapshotLabel) throws PipelineException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public Snapshot getSnapshot(String id) throws PipelineException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public List<SnapshotInfo> getSnapshotsInfo() throws PipelineException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public void deleteSnapshot(String id) throws PipelineException {
      // TODO Auto-generated method stub

    }

    @Override
    public List<PipelineState> getHistory() throws PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public void deleteHistory() {
      // TODO Auto-generated method stub

    }

    @Override
    public Object getMetrics() throws PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public List<Record> getErrorRecords(String stage, int max) throws PipelineRunnerException, PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public List<ErrorMessage> getErrorMessages(
        String stage,
        int max
    ) throws PipelineRunnerException, PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public List<SampledRecord> getSampledRecords(
        String sampleId,
        int max
    ) throws PipelineRunnerException, PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public List<AlertInfo> getAlerts() throws PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public boolean deleteAlert(String alertId) throws PipelineRunnerException, PipelineStoreException {
      // TODO Auto-generated method stub
      return false;
    }

    @Override
    public Collection<CallbackInfo> getSlaveCallbackList(CallbackObjectType callbackObjectType) {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public void close() {
      // TODO Auto-generated method stub

    }

    @Override
    public void updateSlaveCallbackInfo(CallbackInfo callbackInfo) {
      // TODO Auto-generated method stub

    }

    @Override
    public Map getUpdateInfo() {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public String getToken() {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public int getRunnerCount() {
      return 0;
    }

  }

  private static class MockPreviewer implements Previewer {

    private String user;
    private String name;
    private String rev;
    public static int validateConfigsCalled;
    public boolean isValid;

    MockPreviewer(String user, String name, String rev) {
      this.user = user;
      this.name = name;
      this.rev = rev;
    }

    @Override
    public String getId() {
      return user + name + rev;
    }

    @Override
    public String getName() {
      return name;
    }

    @Override
    public String getRev() {
      // TODO Auto-generated method stub
      return rev;
    }

    @Override
    public void validateConfigs(long timeoutMillis) throws PipelineException {
      if (name.equals("ns:name")) {
        isValid = true;
      } else {
        isValid = false;
      }
      validateConfigsCalled++;
    }

    @Override
    public RawPreview getRawSource(
        int maxLength,
        MultivaluedMap<String, String> previewParams
    ) throws PipelineRuntimeException, PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public void start(
        int batches,
        int batchSize,
        boolean skipTargets,
        boolean skipLifecycleEvents,
        String stopStage,
        List<StageOutput> stagesOverride,
        long timeoutMillis
    ) throws PipelineException {

    }

    @Override
    public void stop() {
      // TODO Auto-generated method stub

    }

    @Override
    public boolean waitForCompletion(long timeoutMillis) throws PipelineException {
      // TODO Auto-generated method stub
      return false;
    }

    @Override
    public PreviewStatus getStatus() {
      if (isValid) {
        return PreviewStatus.VALID;
      } else {
        return PreviewStatus.INVALID;
      }
    }

    @Override
    public PreviewOutput getOutput() {
      if (isValid) {
        return new PreviewOutputImpl(PreviewStatus.VALID, null, null, null);
      } else {
        Issues issues = new Issues();
        return new PreviewOutputImpl(PreviewStatus.INVALID, issues, null, null);
      }
    }
  }

  private static class MockPipelineStateStore implements PipelineStateStore {

    public static int getStateCalled;

    @Override
    public PipelineState edited(
        String user,
        String name,
        String rev,
        ExecutionMode executionMode,
        boolean isRemote
    ) throws PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public void delete(String name, String rev) throws PipelineStoreException {
      // TODO Auto-generated method stub

    }

    @Override
    public PipelineState saveState(
        String user,
        String name,
        String rev,
        PipelineStatus status,
        String message,
        Map<String, Object> attributes,
        ExecutionMode executionMode,
        String metrics,
        int retryAttempt,
        long nextRetryTimeStamp
    ) throws PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public PipelineState getState(String name, String rev) throws PipelineStoreException {
      if (getStateCalled == 1) {
        getStateCalled++;
        return new PipelineStateImpl(
            "user",
            name,
            rev,
            PipelineStatus.STOPPED,
            null,
            -1,
            null,
            ExecutionMode.STANDALONE,
            null,
            -1,
            -1
        );
      } else {
        getStateCalled++;
        return new PipelineStateImpl(
            "user",
            name,
            rev,
            PipelineStatus.RUNNING,
            null,
            -1,
            null,
            ExecutionMode.STANDALONE,
            null,
            -1,
            -1
        );
      }
    }

    @Override
    public List<PipelineState> getHistory(
        String name,
        String rev,
        boolean fromBeginning
    ) throws PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public void deleteHistory(String name, String rev) {
      // TODO Auto-generated method stub

    }

    @Override
    public void init() {
      // TODO Auto-generated method stub

    }

    @Override
    public void destroy() {
      // TODO Auto-generated method stub
    }

  }

  private static class MockPipelineStoreTask implements PipelineStoreTask {

    public static int deleteCalled;
    public static int deleteRulesCalled;

    @Override
    public String getName() {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public void init() {
      // TODO Auto-generated method stub

    }

    @Override
    public void run() {
      // TODO Auto-generated method stub

    }

    @Override
    public void waitWhileRunning() throws InterruptedException {
      // TODO Auto-generated method stub

    }

    @Override
    public void stop() {
      // TODO Auto-generated method stub

    }

    @Override
    public Status getStatus() {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public PipelineConfiguration create(
        String user,
        String pipelineId,
        String pipelineTitle,
        String description,
        boolean isRemote
    ) throws PipelineStoreException {
      // TODO Auto-generated method stub
      return new PipelineConfiguration(
          1,
          1,
          "pipelineId",
          UUID.randomUUID(),
          "label",
          "",
          Arrays.asList(new Config("", "")),
          null,
          null,
          null,
          null,
          Collections.emptyList(),
          Collections.emptyList()
      );
    }

    @Override
    public void delete(String name) throws PipelineStoreException {
      deleteCalled++;
    }

    @Override
    public List<PipelineInfo> getPipelines() throws PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public PipelineInfo getInfo(String name) throws PipelineStoreException {
      return new PipelineInfo(name, "title", null, null, null, null, null, null, null, false, null, null, null);
    }

    @Override
    public List<PipelineRevInfo> getHistory(String name) throws PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public PipelineConfiguration load(String name, String tagOrRev) throws PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public boolean hasPipeline(String name) {
      if (deleteCalled == 0) {
        return true;
      } else {
        return false;
      }
    }

    @Override
    public RuleDefinitions retrieveRules(String name, String tagOrRev) throws PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public RuleDefinitions storeRules(
        String pipelineName,
        String tag,
        RuleDefinitions ruleDefinitions
    ) throws PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public boolean deleteRules(String name) throws PipelineStoreException {
      deleteRulesCalled++;
      return false;
    }

    @Override
    public void saveUiInfo(String name, String rev, Map<String, Object> uiInfo) throws PipelineStoreException {
      // TODO Auto-generated method stub

    }

    @Override
    public PipelineConfiguration saveMetadata(
        String user,
        String name,
        String rev,
        Map<String, Object> metadata
    ) throws PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public void registerStateListener(StateEventListener stateListener) {

    }

    @Override
    public PipelineConfiguration save(
        String user,
        String name,
        String tag,
        String tagDescription,
        PipelineConfiguration pipeline
    ) throws PipelineStoreException {
      // TODO Auto-generated method stub
      return null;
    }

    @Override
    public boolean isRemotePipeline(String name, String rev) throws PipelineStoreException {
      // TODO Auto-generated method stub
      return false;
    }

  }

  @Test
  public void testValidateConfigs() throws Exception {
    try {
      AclStoreTask aclStoreTask = Mockito.mock(AclStoreTask.class);
      RemoteDataCollector dataCollector = new RemoteDataCollector(new MockManager(),
          new MockPipelineStoreTask(),
          new MockPipelineStateStore(),
          aclStoreTask,
          new RemoteStateEventListener(new Configuration()),
          null,
          Mockito.mock(AclCacheHelper.class)
      );
      dataCollector.validateConfigs("user", "ns:name", "rev");
      dataCollector.validateConfigs("user1", "ns:name1", "rev1");
      assertEquals(2, MockPreviewer.validateConfigsCalled);
      assertEquals("user" + "ns:name" + "rev", dataCollector.getValidatorList().get(0));
      assertEquals("user1" + "ns:name1" + "rev1", dataCollector.getValidatorList().get(1));
    } finally {
      MockPreviewer.validateConfigsCalled = 0;
    }
  }

  @Test
  public void testStopAndDelete() throws Exception {
    try {
      AclStoreTask aclStoreTask = Mockito.mock(AclStoreTask.class);
      RemoteDataCollector dataCollector = new RemoteDataCollector(new MockManager(),
          new MockPipelineStoreTask(),
          new MockPipelineStateStore(),
          aclStoreTask,
          new RemoteStateEventListener(new Configuration()),
          null,
          Mockito.mock(AclCacheHelper.class)
      );
      dataCollector.stopAndDelete("user", "ns:name", "rev");
      dataCollector.stopAndDelete("user", "ns:name", "rev");
      assertEquals(1, MockRunner.stopCalled);
      assertEquals(1, MockPipelineStoreTask.deleteCalled);
      assertEquals(1, MockPipelineStoreTask.deleteRulesCalled);
      assertEquals(2, MockPipelineStateStore.getStateCalled);
    } finally {
      MockRunner.stopCalled = 0;
      MockPipelineStateStore.getStateCalled = 0;
      MockPipelineStoreTask.deleteCalled = 0;
      MockPipelineStoreTask.deleteRulesCalled = 0;
    }
  }

  @Test
  public void testGetPipelineStatus() throws Exception {
    try {
      RuntimeInfo runtimeInfo = Mockito.mock(RuntimeInfo.class);
      AclStoreTask aclStoreTask = Mockito.mock(AclStoreTask.class);
      File testFolder = tempFolder.newFolder();
      Mockito.when(runtimeInfo.getDataDir()).thenReturn(testFolder.getAbsolutePath());
      OffsetFileUtil.saveOffsets(runtimeInfo, "ns:name", "rev", Collections.singletonMap(Source.POLL_SOURCE_OFFSET_KEY, "offset:100"));
      OffsetFileUtil.saveOffsets(runtimeInfo, "ns:name1", "rev1", Collections.singletonMap(Source.POLL_SOURCE_OFFSET_KEY, "offset:101"));
      OffsetFileUtil.saveOffsets(runtimeInfo, "ns:name2", "rev1", Collections.singletonMap(Source.POLL_SOURCE_OFFSET_KEY, "offset:102"));

      RemoteDataCollector dataCollector = new RemoteDataCollector(new MockManager(),
          new MockPipelineStoreTask(),
          new MockPipelineStateStore(),
          aclStoreTask,
          new RemoteStateEventListener(new Configuration()),
          runtimeInfo,
          Mockito.mock(AclCacheHelper.class)
      );
      dataCollector.init();
      dataCollector.validateConfigs("user", "ns:name", "rev");
      dataCollector.validateConfigs("user1", "ns:name1", "rev1");
      Collection<PipelineAndValidationStatus> collectionPipelines = dataCollector.getPipelines();
      assertEquals(4, collectionPipelines.size());
      for (PipelineAndValidationStatus validationStatus : collectionPipelines) {
        assertTrue(validationStatus.getName().equals("ns:name") || validationStatus.getName().equals("ns:name1") ||
            validationStatus.getName().equals(
            "ns:name2") || validationStatus.getName().equals("local"));
        if (validationStatus.getName().equals("ns:name")) {
          assertEquals("title", validationStatus.getTitle());
          assertEquals("rev", validationStatus.getRev());
          assertEquals(PipelineStatus.EDITED, validationStatus.getPipelineStatus());
          assertEquals(ValidationStatus.VALID, validationStatus.getValidationStatus());
          assertNull(validationStatus.getMessage());
          assertNull(validationStatus.getIssues());
        } else if (validationStatus.getName().equals("ns:name1")) {
          assertEquals("rev1", validationStatus.getRev());
          assertEquals(PipelineStatus.EDITED, validationStatus.getPipelineStatus());
          assertEquals(ValidationStatus.INVALID, validationStatus.getValidationStatus());
          assertEquals(0, validationStatus.getIssues().getIssues().size());
        } else if (validationStatus.getName().equals("ns:name2")) {
          assertEquals("rev1", validationStatus.getRev());
          assertEquals(PipelineStatus.RUNNING, validationStatus.getPipelineStatus());
          assertNull(validationStatus.getValidationStatus());
          assertNull(validationStatus.getIssues());
        } else {
          assertEquals("rev1", validationStatus.getRev());
          assertEquals(PipelineStatus.RUNNING, validationStatus.getPipelineStatus());
          assertNull(validationStatus.getValidationStatus());
          assertNull(validationStatus.getIssues());
        }
      }
      assertTrue(dataCollector.getValidatorList().isEmpty());
    } finally {
      MockPreviewer.validateConfigsCalled = 0;
    }
  }

  @Test
  public void testAclOnSavePipeline() throws Exception {
    RuntimeInfo runtimeInfo = Mockito.mock(RuntimeInfo.class);
    AclStoreTask aclStoreTask = Mockito.mock(AclStoreTask.class);
    RemoteDataCollector dataCollector = new RemoteDataCollector(new MockManager(),
        new MockPipelineStoreTask(),
        new MockPipelineStateStore(),
        aclStoreTask,
        new RemoteStateEventListener(new Configuration()),
        runtimeInfo,
        Mockito.mock(AclCacheHelper.class)
    );
    File testFolder = tempFolder.newFolder();
    Mockito.when(runtimeInfo.getDataDir()).thenReturn(testFolder.getAbsolutePath());
    Acl acl = new Acl();
    SourceOffset sourceOffset = new SourceOffset();
    sourceOffset.setOffset("offset:1000");
    new SourceOffsetUpgrader().upgrade(sourceOffset);
    dataCollector.savePipeline("user", "foo", "0", "", sourceOffset, Mockito.mock(PipelineConfiguration.class), null,
        acl);
    Mockito.verify(aclStoreTask, Mockito.times(1)).saveAcl(Mockito.eq("foo"), Mockito.eq(acl));
  }

  @Test
  public void testSyncAcl() throws Exception {
    RuntimeInfo runtimeInfo = Mockito.mock(RuntimeInfo.class);
    AclStoreTask aclStoreTask = Mockito.mock(AclStoreTask.class);
    PipelineStoreTask pipelineStoreTask = Mockito.mock(MockPipelineStoreTask.class);
    RemoteDataCollector dataCollector = new RemoteDataCollector(new MockManager(),
        pipelineStoreTask,
        new MockPipelineStateStore(),
        aclStoreTask,
        new RemoteStateEventListener(new Configuration()),
        runtimeInfo,
        Mockito.mock(AclCacheHelper.class)
    );
    File testFolder = tempFolder.newFolder();
    Mockito.when(runtimeInfo.getDataDir()).thenReturn(testFolder.getAbsolutePath());
    Mockito.when(pipelineStoreTask.hasPipeline(Mockito.anyString())).thenReturn(true);
    Acl acl = new Acl();
    String name = "remote:pipeline";
    acl.setResourceId(name);
    dataCollector.syncAcl(acl);
    Mockito.verify(aclStoreTask, Mockito.times(1)).saveAcl(Mockito.eq(name), Mockito.eq(acl));
  }

  @Test
  public void testSavePipelineOffset() throws Exception {
    RuntimeInfo runtimeInfo = Mockito.mock(RuntimeInfo.class);
    AclStoreTask aclStoreTask = Mockito.mock(AclStoreTask.class);
    RemoteDataCollector dataCollector = new RemoteDataCollector(new MockManager(),
        new MockPipelineStoreTask(),
        new MockPipelineStateStore(),
        aclStoreTask,
        new RemoteStateEventListener(new Configuration()),
        runtimeInfo,
        Mockito.mock(AclCacheHelper.class)
    );
    File testFolder = tempFolder.newFolder();
    Mockito.when(runtimeInfo.getDataDir()).thenReturn(testFolder.getAbsolutePath());
    SourceOffset sourceOffset = new SourceOffset();
    sourceOffset.setOffset("offset:1000");
    new SourceOffsetUpgrader().upgrade(sourceOffset);
    dataCollector.savePipeline("user", "foo", "0", "", sourceOffset, Mockito.mock(PipelineConfiguration.class), null,
        new Acl());
    assertTrue("Offset File doesn't exist", OffsetFileUtil.getPipelineOffsetFile(runtimeInfo, "foo", "0").exists());
    assertEquals(
        sourceOffset.getOffsets().get(Source.POLL_SOURCE_OFFSET_KEY),
        OffsetFileUtil.getOffsets(runtimeInfo, "foo", "0").get(Source.POLL_SOURCE_OFFSET_KEY)
    );
  }

  @Test
  public void testRemotePipelines() throws Exception {
    RuntimeInfo runtimeInfo = Mockito.mock(RuntimeInfo.class);
    AclStoreTask aclStoreTask = Mockito.mock(AclStoreTask.class);
    RemoteStateEventListener remoteStateEventListener = Mockito.mock(RemoteStateEventListener.class);
    PipelineStoreTask pipelineStoreTask = Mockito.mock(MockPipelineStoreTask.class);
    RemoteDataCollector dataCollector = new RemoteDataCollector(new MockManager(),
        pipelineStoreTask,
        new MockPipelineStateStore(),
        aclStoreTask,
        remoteStateEventListener,
        runtimeInfo,
        Mockito.mock(AclCacheHelper.class)
    );
    List<PipelineState> pipelineStates = new ArrayList<>();
    pipelineStates.add(new PipelineStateImpl("user",
        "name",
        "rev",
        PipelineStatus.RUNNING,
        "message",
        -1,
        new HashMap<String, Object>(),
        ExecutionMode.STANDALONE,
        "",
        -1,
        -1
    ));
    File testFolder = tempFolder.newFolder();
    Mockito.when(runtimeInfo.getDataDir()).thenReturn(testFolder.getAbsolutePath());
    Mockito.when(pipelineStoreTask.hasPipeline(Mockito.anyString())).thenReturn(false);
    Mockito.when(remoteStateEventListener.getPipelineStateEvents()).thenReturn(Arrays.<Pair<PipelineState,
        Map<String, String>>>asList(
        new ImmutablePair<>(pipelineStates.get(0), Collections.singletonMap(Source.POLL_SOURCE_OFFSET_KEY, "offset:1000"))));
    List<PipelineAndValidationStatus> pipelineAndValidationStatuses = dataCollector.getRemotePipelinesWithChanges();
    assertEquals(1, pipelineAndValidationStatuses.size());
    PipelineAndValidationStatus pipelineAndValidationStatus = pipelineAndValidationStatuses.get(0);
    assertEquals("name", pipelineAndValidationStatus.getName());
    assertNull(pipelineAndValidationStatus.getTitle());
    assertEquals("rev", pipelineAndValidationStatus.getRev());
    assertEquals(PipelineStatus.RUNNING, pipelineAndValidationStatus.getPipelineStatus());
    assertEquals(false, pipelineAndValidationStatus.isClusterMode());
    assertTrue(pipelineAndValidationStatus.getWorkerInfos().isEmpty());
    assertTrue(pipelineAndValidationStatus.isRemote());
    assertEquals("message", pipelineAndValidationStatus.getMessage());
    // "{\n" + "  \"offsets\" : {\n" + "    \"$com.streamsets.datacollector.pollsource.offset$\" : \"offset:1000\"\n" + "  },\n" + "  \"version\" : 2\n" + "}"

    SourceOffsetJson sourceOffsetJson = ObjectMapperFactory.get().readValue(
        pipelineAndValidationStatus.getOffset(),
        SourceOffsetJson.class
    );
    assertNotNull(sourceOffsetJson);
    assertEquals(2, sourceOffsetJson.getVersion());
    assertEquals("offset:1000", sourceOffsetJson.getOffsets().get(Source.POLL_SOURCE_OFFSET_KEY));
    assertNull(pipelineAndValidationStatus.getValidationStatus());
  }

  @Test
  public void testRunnerCount() throws Exception {
    Manager manager = Mockito.mock(StandaloneAndClusterPipelineManager.class);
    PipelineStoreTask pipelineStoreTask = Mockito.mock(PipelineStoreTask.class);
    RemoteDataCollector dataCollector = Mockito.spy(new RemoteDataCollector(manager,
        pipelineStoreTask,
        Mockito.mock(PipelineStateStore.class),
        Mockito.mock(AclStoreTask.class),
        Mockito.mock(RemoteStateEventListener.class),
        Mockito.mock(RuntimeInfo.class),
        Mockito.mock(AclCacheHelper.class)
    ));
    PipelineState pipelineStatus1 = new PipelineStateImpl("user",
        "ns:name",
        "rev",
        PipelineStatus.RUNNING,
        null,
        System.currentTimeMillis(),
        null,
        ExecutionMode.STANDALONE,
        null,
        0,
        -1
    );
    Mockito.when(manager.isPipelineActive(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
    Mockito.when(manager.getPipelines()).thenReturn(Arrays.asList(pipelineStatus1));
    Mockito.when(pipelineStoreTask.getInfo(Mockito.anyString())).thenReturn(Mockito.mock(PipelineInfo.class));
    Runner runner = Mockito.mock(Runner.class);
    Mockito.when(runner.getRunnerCount()).thenReturn(10);
    Mockito.when(manager.getRunner(Mockito.anyString(), Mockito.anyString())).thenReturn(runner);
    assertEquals(1, dataCollector.getPipelines().size());
    PipelineAndValidationStatus pipelineAndValidationStatus = dataCollector.getPipelines().iterator().next();
    assertEquals(10, pipelineAndValidationStatus.getRunnerCount());
  }
}


text:
require 'helper'

describe Toy::Attributes do
  uses_constants('User', 'Game', 'Move', 'Tile')

  before do
    Game.embedded_list(:moves)
    Move.embedded_list(:tiles)
  end

  describe "including" do
    it "adds id attribute" do
      User.attributes.keys.should == ['id']
    end
  end

  describe ".attributes" do
    it "defaults to hash with id" do
      User.attributes.keys.should == ['id']
    end
  end

  describe "#persisted_attributes" do
    before do
      Game.embedded_list(:moves)
      @over    = Game.attribute(:over, Boolean)
      @score   = Game.attribute(:creator_score, Integer, :virtual => true)
      @abbr    = Game.attribute(:super_secret_hash, String, :abbr => :ssh)
      @rewards = Game.attribute(:rewards, Set)
      @game    = Game.new({
        :over          => true,
        :creator_score => 20,
        :rewards       => %w(twigs berries).to_set,
        :ssh           => 'h4x',
        :moves         => [Move.new, Move.new],
      })
    end

    it "includes persisted attributes" do
      @game.persisted_attributes.should have_key('over')
    end

    it "includes abbreviated names for abbreviated attributes" do
      @game.persisted_attributes.should have_key('ssh')
    end

    it "does not include full names for abbreviated attributes" do
      @game.persisted_attributes.should_not have_key('super_secret_hash')
    end

    it "includes embedded" do
      @game.persisted_attributes.should have_key('moves')
    end

    it "does not include virtual attributes" do
      @game.persisted_attributes.should_not have_key(:creator_score)
    end

    it "includes to_store values for attributes" do
      @game.persisted_attributes['rewards'].should be_instance_of(Array)
      @game.persisted_attributes['rewards'].should == @rewards.to_store(@game.rewards)
    end
  end

  describe ".defaulted_attributes" do
    before do
      @name = User.attribute(:name, String)
      @age  = User.attribute(:age, Integer, :default => 10)
    end

    it "includes attributes with a default" do
      User.defaulted_attributes.should include(@age)
    end

    it "excludes attributes without a default" do
      User.defaulted_attributes.should_not include(@name)
    end
  end

  describe ".attribute?" do
    before do
      User.attribute :age, Integer
    end

    it "returns true if attribute (symbol)" do
      User.attribute?(:age).should be_true
    end

    it "returns true if attribute (string)" do
      User.attribute?('age').should be_true
    end

    it "returns false if not attribute" do
      User.attribute?(:foobar).should be_false
    end
  end

  describe "#initialize" do
    before do
      User.attribute :name, String
      User.attribute :age,  Integer
    end

    it "writes id" do
      id = User.new.id
      id.should_not be_nil
      id.size.should == 36
    end

    it "does not attempt to set id if already set" do
      user = User.new(:id => 'frank')
      user.id.should == 'frank'
    end

    it "sets attributes" do
      instance = User.new(:name => 'John', :age => 28)
      instance.name.should == 'John'
      instance.age.should  == 28
    end

    it "sets defaults" do
      User.attribute(:awesome, Boolean, :default => true)
      User.new.awesome.should be_true
    end

    it "does not fail with nil" do
      User.new(nil).should be_instance_of(User)
    end
  end

  describe "#initialize_from_database" do
    before do
      User.attribute(:age, Integer, :default => 20)
      @user = User.allocate
    end

    it "sets new record to false" do
      @user.initialize_from_database
      @user.should_not be_new_record
    end

    it "sets attributes" do
      @user.initialize_from_database('age' => 21)
    end

    it "sets defaults" do
      @user.initialize_from_database
      @user.age.should == 20
    end

    it "does not fail with nil" do
      @user.initialize_from_database(nil).should == @user
    end

    it "returns self" do
      @user.initialize_from_database.should == @user
    end
  end

  describe "#attributes" do
    it "defaults to hash with id" do
      attrs = Model().new.attributes
      attrs.keys.should == ['id']
    end

    it "includes all attributes that are not nil" do
      User.attribute(:name, String)
      User.attribute(:active, Boolean, :default => true)
      user = User.new
      user.attributes.should == {
        'id'     => user.id,
        'active' => true,
      }
    end

    it "does not include embedded documents" do
      game = Game.new(:moves => [Move.new(:tiles => [Tile.new])])
      game.attributes.should_not have_key('moves')
    end
  end

  describe "#attributes=" do
    it "sets attributes if present" do
      User.attribute :age, Integer
      record = User.new
      record.attributes = {:age => 20}
      record.age.should == 20
    end

    it "does nothing if nil" do
      record = User.new
      lambda { record.attributes = nil }.should_not raise_error
    end

    it "works with accessors that are not keys" do
      User.class_eval { attr_accessor :foo }
      record = User.new(:foo => 'oof')
      record.foo.should == 'oof'
    end

    it "ignores keys that are not attributes and do not have accessors defined" do
      lambda { User.new(:taco => 'bell') }.should_not raise_error
    end
  end

  describe "reading an attribute" do
    before do
      User.attribute(:info, Hash)
      @user = User.new(:info => {'name' => 'John'})
    end

    it "returns the same instance" do
      @user.info.should equal(@user.info)
    end
  end

  describe "declaring an attribute" do
    before do
      User.attribute :name, String
      User.attribute :age, Integer
    end

    it "adds attribute to attributes" do
      User.attributes['name'].should == Toy::Attribute.new(User, :name, String)
      User.attributes[:name].should be_nil
      User.attributes['age'].should  == Toy::Attribute.new(User, :age, Integer)
      User.attributes[:age].should be_nil
    end

    it "adds accessors" do
      record = User.new
      record.name = 'John'
      record.name.should == 'John'
    end

    it "converts to attribute type" do
      record = User.new
      record.age = '12'
      record.age.should == 12
    end

    it "adds query-ers" do
      record = User.new
      record.name?.should be_false
      record.name = 'John'
      record.name?.should be_true
    end

    it "knows if it responds to attribute method" do
      record = User.new
      record.should respond_to(:name)
      record.should respond_to(:name=)
      record.should respond_to(:name?)
    end

    it "know if it does not respond to method" do
      record = User.new
      record.should_not respond_to(:foobar)
    end

    it "aliases [] to read_attribute" do
      record = User.new(:name => 'John')
      record[:name].should == 'John'
    end

    it "aliases []= to write_attribute" do
      record = User.new
      record[:name] = 'John'
      record.name.should == 'John'
    end
  end

  describe "declaring an attribute with a default" do
    before do
      User.attribute :active, Boolean, :default => true
    end

    it "adds attribute to attributes" do
      attribute = Toy::Attribute.new(User, :active, Boolean, {:default => true})
      User.attributes['active'].should == attribute
    end

    it "defaults value when initialized" do
      User.new.active.should be(true)
    end

    it "overrides default if present" do
      User.new(:active => false).active.should be(false)
    end
  end

  describe "declaring an attribute with an abbreviation" do
    before do
      User.attribute(:twitter_access_token, String, :abbr => 'tat')
    end

    it "aliases reading to abbreviation" do
      user = User.new
      user.twitter_access_token = '1234'
      user.tat.should == '1234'
    end

    it "aliases writing to abbreviation" do
      user = User.new
      user.tat = '1234'
      user.twitter_access_token.should == '1234'
    end

    it "persists to store using abbreviation" do
      user = User.create(:twitter_access_token => '1234')
      raw = user.store.read(user.store_key)
      raw['tat'].should == '1234'
      raw.should_not have_key('twitter_access_token')
    end

    it "loads from store correctly" do
      user = User.create(:twitter_access_token => '1234')
      user = User.get(user.id)
      user.twitter_access_token.should == '1234'
      user.tat.should == '1234'
    end
  end

  describe "#reload" do
    before do
      User.attribute(:name, String)
      @user = User.create(:name => 'John')
    end
    let(:user) { @user }

    it "reloads record from the database" do
      user.name = 'Steve'
      user.reload
      user.name.should == 'John'
    end

    it "is still persisted" do
      user.should be_persisted
      user.reload
      user.should be_persisted
    end

    it "returns the record" do
      user.name = 'Steve'
      user.reload.should equal(user)
    end

    it "resets instance variables" do
      user.instance_variable_set("@foo", true)
      user.reload
      user.instance_variable_get("@foo").should be_nil
    end

    it "resets lists" do
      User.list(:games)
      game = Game.create
      user.update_attributes(:games => [game])
      user.games = []
      user.games.should == []
      user.reload
      user.games.should == [game]
    end

    it "resets references" do
      Game.reference(:user)
      game = Game.create(:user => user)
      game.user = nil
      game.user.should be_nil
      game.reload
      game.user.should == user
    end

    it "raises NotFound if does not exist" do
      user.destroy
      lambda { user.reload }.should raise_error(Toy::NotFound)
    end

    it "reloads defaults" do
      User.attribute(:skills, Array)
      @user.reload
      @user.skills.should == []
    end
  end

  describe "Initialization of array attributes" do
    before do
      User.attribute(:skills, Array)
    end

    it "initializes to empty array" do
      User.new.skills.should == []
    end
  end
end

redpajama_set_name: RedPajamaGithub


text:
package com.netease.nim.demo.common.infra;

public class TaskObservable extends Observable<TaskObserver> implements TaskObserver {
	@Override
	public void onTaskResult(Task task, Object[] results) {
		for (TaskObserver observer : getObservers()) {
			observer.onTaskResult(task, results);
		}
	}

	@Override
	public void onTaskProgress(Task task, Object[] params) {
		for (TaskObserver observer : getObservers()) {
			observer.onTaskProgress(task, params);
		}
	}
}


text:
from . import web
from functools import wraps
from flask import request, Response, redirect

def check_auth(username, password):
    """This function is called to check if a username /
    password combination is valid.
    """
    return username == 'knoydart' and password == 'power'

def authenticate():
    """Sends a 401 response that enables basic auth"""
    return Response(
    'Could not verify your access level for that URL.\n'
    'You have to login with proper credentials', 401,
    {'WWW-Authenticate': 'Basic realm="Login Required"'})

def requires_auth(f):
    @wraps(f)
    def decorated(*args, **kwargs):
        auth = request.authorization
        if not auth or not check_auth(auth.username, auth.password):
            return authenticate()
        return f(*args, **kwargs)
    return decorated

@web.route("/")
@web.route("/chart-simple")
def index():
    return web.send_static_file('simple.html')

@web.route("/chart-advanced")
def index_adv():
    return web.send_static_file('advanced.html')

@web.route("/chart-tech")
def index_tech():
    return web.send_static_file('tech.html')

@web.route("/api/")
def api_info():
    return web.send_static_file('api.html')

@web.route("/favicon.ico", defaults={'file': 'favicon.ico'})
@web.route("/favicons/<file>")
def get_favicon(file):
    return web.send_static_file('favicons/' + file)

@web.route("/css/<filename>.css")
def get_css(filename):
    return web.send_static_file('css/' + filename + '.css')

@web.route("/js/<filename>.js")
def get_js(filename):
    return web.send_static_file('js/' + filename + '.js')

@web.route("/images/<file>")
def get_image(file):
    return web.send_static_file('images/' + file)

@web.route("/fonts/<file>")
def get_font(file):
    return web.send_static_file('fonts/' + file)

@web.route("/fancybox/<file>")
def get_fancybox(file):
    return web.send_static_file('fancybox/' + file)

@web.route("/footer.html")
def get_footer():
    return web.send_static_file('footer.html')

@web.route("/report.csv")
@requires_auth
def get_report():
    return redirect("http://knoydart.modulo.ee/api/v0/readings/pages/?page=lastMonth", code=302)


text:
{% extends "base.html" %}

{% from "macros.html" import render_field with context %}

{% block content %}

Propose a Food Resource

	<form action="" method="POST" role="form" name="submit_food_resource">
	    {{ form.hidden_tag() }}

    	{% if form.location_type.errors %}
            {% for e in form.location_type.errors %}
                {% if e %}
                    {{ e }}
                {% endif %}
            {% endfor %}
        {% endif %}

				If you are a food provider, please use this form to submit an update to an existing resource or to add a new resource to the map. Once you submit this information and your pin has been approved, your site's resource will appear on the map.

				If you have any questions, please send us an e-mail at phillyfoodinfo@gmail.com.

					Required fields.

		        	{% if additional_errors %}
		                {% for e in additional_errors %}
		                    {% if e %}
		                        {{ e }}
		                    {% endif %}
		                {% endfor %}
		            {% endif %}

Site Contact Information

		      	This information will appear on the map within your site pin.

	    {{ render_field(form.name) }}

		{{ render_field(form.address_line1) }}

	  	{{ render_field(form.address_line2) }}

		{{ render_field(form.address_city) }}

		{{ render_field(form.address_state) }}

		{{ render_field(form.address_zip_code) }}

		{{ render_field(form.phone_number) }}

		{{ render_field(form.website) }}

Type of Food Resource

		{{ render_field(form.location_type) }}

Days / Hours of Operation

		{{ render_field(form.are_hours_available) }}

		{% for multi_timeslot_form in form.daily_timeslots %}
		{% set day_of_week = days_of_week[loop.index0] %}
		{% set is_open = form.is_open[loop.index0].is_open %}
		{% set day_of_week_index = loop.index0 %}

		{{ form.is_open[loop.index0].form.hidden_tag() }}
		{{ multi_timeslot_form.form.hidden_tag() }}

			      			{{ day_of_week.name }}

{{ is_open()|safe }}
					        	{% if is_open.errors %}
					                {% for e in is_open.errors %}
					                    {% if e %}
					                        {{ e }}
					                    {% endif %}
					                {% endfor %}
					            {% endif %}

			      			{% set field = multi_timeslot_form.num_timeslots %}

			      					{% if multi_timeslot_form.num_timeslots.flags.required %}
								      	{{ field.label(class_='required') }}
								    {% else %}
										{{ field.label }}
								    {% endif %}

{{ field()|safe }}
										{% if field.errors %}
											{% for e in field.errors %}
												{% if e %}
													{{ e }}
												{% endif %}
											{% endfor %}
										{% endif %}

			      		{% for timeslot_form in multi_timeslot_form.timeslots %}
		      			{% set timeslot_index = loop.index0 %}
			      			{{ timeslot_form.form.hidden_tag() }}

									{{ timeslot_form.starts_at.label }}

{{ timeslot_form.starts_at()|safe }}
										{% if timeslot_form.starts_at.errors %}
											{% for e in timeslot_form.starts_at.errors %}
												{% if e %}
													{{ e }}
												{% endif %}
											{% endfor %}
										{% endif %}

									{{ timeslot_form.ends_at.label }}

{{ timeslot_form.ends_at()|safe }}
										{% if timeslot_form.ends_at.errors %}
											{% for e in timeslot_form.ends_at.errors %}
												{% if e %}
													{{ e }}
												{% endif %}
											{% endfor %}
										{% endif %}

							{% endfor %}

		{% endfor %}

Additional Information

		{% for boolean in form.booleans %}
			{{ boolean.form.hidden_tag() }}
			{{ render_field(boolean.value) }}
		{% endfor %}

		{{ render_field(form.additional_information) }}

How can we contact you, if needed?

		      	This will NOT appear on the map and will only be used if we need to
				contact you about information you submitted.

		{{ render_field(form.your_name) }}

		{{ render_field(form.your_phone_number) }}

		{{ render_field(form.your_email_address) }}

		{{ render_field(form.notes) }}

		{{ render_field(form.recaptcha) }}

	          <input type=submit class="button radius small" value=Submit>

	</form>

{% endblock %}


text:
package org.apache.cassandra.db.compaction;

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.UUID;

import junit.framework.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.apache.cassandra.OrderedJUnit4ClassRunner;
import org.apache.cassandra.SchemaLoader;
import org.apache.cassandra.Util;
import org.apache.cassandra.UpdateBuilder;
import org.apache.cassandra.db.ColumnFamilyStore;
import org.apache.cassandra.db.Keyspace;
import org.apache.cassandra.dht.Range;
import org.apache.cassandra.dht.Token;
import org.apache.cassandra.exceptions.ConfigurationException;
import org.apache.cassandra.io.sstable.ISSTableScanner;
import org.apache.cassandra.io.sstable.format.SSTableReader;
import org.apache.cassandra.notifications.SSTableAddedNotification;
import org.apache.cassandra.notifications.SSTableRepairStatusChanged;
import org.apache.cassandra.repair.RepairJobDesc;
import org.apache.cassandra.repair.Validator;
import org.apache.cassandra.schema.CompactionParams;
import org.apache.cassandra.schema.KeyspaceParams;
import org.apache.cassandra.service.ActiveRepairService;
import org.apache.cassandra.utils.FBUtilities;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

@RunWith(OrderedJUnit4ClassRunner.class)
public class LeveledCompactionStrategyTest
{
    private static final Logger logger = LoggerFactory.getLogger(LeveledCompactionStrategyTest.class);

    private static final String KEYSPACE1 = "LeveledCompactionStrategyTest";
    private static final String CF_STANDARDDLEVELED = "StandardLeveled";
    private Keyspace keyspace;
    private ColumnFamilyStore cfs;

    @BeforeClass
    public static void defineSchema() throws ConfigurationException
    {
        SchemaLoader.prepareServer();
        SchemaLoader.createKeyspace(KEYSPACE1,
                                    KeyspaceParams.simple(1),
                                    SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARDDLEVELED)
                                                .compaction(CompactionParams.lcs(Collections.singletonMap("sstable_size_in_mb", "1"))));
        }

    @Before
    public void enableCompaction()
    {
        keyspace = Keyspace.open(KEYSPACE1);
        cfs = keyspace.getColumnFamilyStore(CF_STANDARDDLEVELED);
        cfs.enableAutoCompaction();
    }

    /**
     * Since we use StandardLeveled CF for every test, we want to clean up after the test.
     */
    @After
    public void truncateSTandardLeveled()
    {
        cfs.truncateBlocking();
    }

    /**
     * Ensure that the grouping operation preserves the levels of grouped tables
     */
    @Test
    public void testGrouperLevels() throws Exception{
        ByteBuffer value = ByteBuffer.wrap(new byte[100 * 1024]); // 100 KB value, make it easy to have multiple files

        //Need entropy to prevent compression so size is predictable with compression enabled/disabled
        new Random().nextBytes(value.array());

        // Enough data to have a level 1 and 2
        int rows = 40;
        int columns = 20;

        // Adds enough data to trigger multiple sstable per level
        for (int r = 0; r < rows; r++)
        {
            UpdateBuilder update = UpdateBuilder.create(cfs.metadata, String.valueOf(r));
            for (int c = 0; c < columns; c++)
                update.newRow("column" + c).add("val", value);
            update.applyUnsafe();
            cfs.forceBlockingFlush();
        }

        waitForLeveling(cfs);
        CompactionStrategyManager strategy =  cfs.getCompactionStrategyManager();
        // Checking we're not completely bad at math
        int l1Count = strategy.getSSTableCountPerLevel()[1];
        int l2Count = strategy.getSSTableCountPerLevel()[2];
        if (l1Count == 0 || l2Count == 0)
        {
            logger.error("L1 or L2 has 0 sstables. Expected > 0 on both.");
            logger.error("L1: " + l1Count);
            logger.error("L2: " + l2Count);
            Assert.fail();
        }

        Collection<Collection<SSTableReader>> groupedSSTables = cfs.getCompactionStrategyManager().groupSSTablesForAntiCompaction(cfs.getLiveSSTables());
        for (Collection<SSTableReader> sstableGroup : groupedSSTables)
        {
            int groupLevel = -1;
            Iterator<SSTableReader> it = sstableGroup.iterator();
            while (it.hasNext())
            {

                SSTableReader sstable = it.next();
                int tableLevel = sstable.getSSTableLevel();
                if (groupLevel == -1)
                    groupLevel = tableLevel;
                assert groupLevel == tableLevel;
            }
        }

    }

    /*
     * This exercises in particular the code of #4142
     */
    @Test
    public void testValidationMultipleSSTablePerLevel() throws Exception
    {
        byte [] b = new byte[100 * 1024];
        new Random().nextBytes(b);
        ByteBuffer value = ByteBuffer.wrap(b); // 100 KB value, make it easy to have multiple files

        // Enough data to have a level 1 and 2
        int rows = 20;
        int columns = 10;

        // Adds enough data to trigger multiple sstable per level
        for (int r = 0; r < rows; r++)
        {
            UpdateBuilder update = UpdateBuilder.create(cfs.metadata, String.valueOf(r));
            for (int c = 0; c < columns; c++)
                update.newRow("column" + c).add("val", value);
            update.applyUnsafe();
            cfs.forceBlockingFlush();
        }

        waitForLeveling(cfs);
        CompactionStrategyManager strategy =  cfs.getCompactionStrategyManager();
        // Checking we're not completely bad at math
        assertTrue(strategy.getSSTableCountPerLevel()[1] > 0);
        assertTrue(strategy.getSSTableCountPerLevel()[2] > 0);

        Range<Token> range = new Range<>(Util.token(""), Util.token(""));
        int gcBefore = keyspace.getColumnFamilyStore(CF_STANDARDDLEVELED).gcBefore(FBUtilities.nowInSeconds());
        UUID parentRepSession = UUID.randomUUID();
        ActiveRepairService.instance.registerParentRepairSession(parentRepSession, Arrays.asList(cfs), Arrays.asList(range), false);
        RepairJobDesc desc = new RepairJobDesc(parentRepSession, UUID.randomUUID(), KEYSPACE1, CF_STANDARDDLEVELED, Arrays.asList(range));
        Validator validator = new Validator(desc, FBUtilities.getBroadcastAddress(), gcBefore);
        CompactionManager.instance.submitValidation(cfs, validator).get();
    }

    /**
     * wait for leveled compaction to quiesce on the given columnfamily
     */
    private void waitForLeveling(ColumnFamilyStore cfs) throws InterruptedException
    {
        CompactionStrategyManager strategy =  cfs.getCompactionStrategyManager();
        // L0 is the lowest priority, so when that's done, we know everything is done
        while (strategy.getSSTableCountPerLevel()[0] > 1)
            Thread.sleep(100);

        // in AbstractCompationStrategy.replaceSSTables() first we remove and then we add sstables so wait a little bit longer
        Thread.sleep(10);
    }

    @Test
    public void testCompactionProgress() throws Exception
    {
        // make sure we have SSTables in L1
        byte [] b = new byte[100 * 1024];
        new Random().nextBytes(b);
        ByteBuffer value = ByteBuffer.wrap(b);
        int rows = 2;
        int columns = 10;
        for (int r = 0; r < rows; r++)
        {
            UpdateBuilder update = UpdateBuilder.create(cfs.metadata, String.valueOf(r));
            for (int c = 0; c < columns; c++)
                update.newRow("column" + c).add("val", value);
            update.applyUnsafe();
            cfs.forceBlockingFlush();
        }

        waitForLeveling(cfs);
        LeveledCompactionStrategy strategy = (LeveledCompactionStrategy) (cfs.getCompactionStrategyManager()).getStrategies().get(1);
        assert strategy.getLevelSize(1) > 0;

        // get LeveledScanner for level 1 sstables
        Collection<SSTableReader> sstables = strategy.manifest.getLevel(1);
        List<ISSTableScanner> scanners = strategy.getScanners(sstables).scanners;
        assertEquals(1, scanners.size()); // should be one per level
        ISSTableScanner scanner = scanners.get(0);
        // scan through to the end
        while (scanner.hasNext())
            scanner.next();

        // scanner.getCurrentPosition should be equal to total bytes of L1 sstables
        assertEquals(scanner.getCurrentPosition(), SSTableReader.getTotalUncompressedBytes(sstables));
    }

    @Test
    public void testMutateLevel() throws Exception
    {
        ByteBuffer value = ByteBuffer.wrap(new byte[100 * 1024]); // 100 KB value, make it easy to have multiple files

        // Enough data to have a level 1 and 2
        int rows = 20;
        int columns = 10;

        // Adds enough data to trigger multiple sstable per level
        for (int r = 0; r < rows; r++)
        {
            UpdateBuilder update = UpdateBuilder.create(cfs.metadata, String.valueOf(r));
            for (int c = 0; c < columns; c++)
                update.newRow("column" + c).add("val", value);
            update.applyUnsafe();
            cfs.forceBlockingFlush();
        }
        waitForLeveling(cfs);
        cfs.forceBlockingFlush();
        LeveledCompactionStrategy strategy = (LeveledCompactionStrategy) ( cfs.getCompactionStrategyManager()).getStrategies().get(1);
        cfs.disableAutoCompaction();

        while(CompactionManager.instance.isCompacting(Arrays.asList(cfs)))
            Thread.sleep(100);

        for (SSTableReader s : cfs.getLiveSSTables())
        {
            assertTrue(s.getSSTableLevel() != 6);
            strategy.manifest.remove(s);
            s.descriptor.getMetadataSerializer().mutateLevel(s.descriptor, 6);
            s.reloadSSTableMetadata();
            strategy.manifest.add(s);
        }
        // verify that all sstables in the changed set is level 6
        for (SSTableReader s : cfs.getLiveSSTables())
            assertEquals(6, s.getSSTableLevel());

        int[] levels = strategy.manifest.getAllLevelSize();
        // verify that the manifest has correct amount of sstables
        assertEquals(cfs.getLiveSSTables().size(), levels[6]);
    }

    @Test
    public void testNewRepairedSSTable() throws Exception
    {
        byte [] b = new byte[100 * 1024];
        new Random().nextBytes(b);
        ByteBuffer value = ByteBuffer.wrap(b); // 100 KB value, make it easy to have multiple files

        // Enough data to have a level 1 and 2
        int rows = 20;
        int columns = 10;

        // Adds enough data to trigger multiple sstable per level
        for (int r = 0; r < rows; r++)
        {
            UpdateBuilder update = UpdateBuilder.create(cfs.metadata, String.valueOf(r));
            for (int c = 0; c < columns; c++)
                update.newRow("column" + c).add("val", value);
            update.applyUnsafe();
            cfs.forceBlockingFlush();
        }
        waitForLeveling(cfs);
        cfs.disableAutoCompaction();

        while(CompactionManager.instance.isCompacting(Arrays.asList(cfs)))
            Thread.sleep(100);

        CompactionStrategyManager strategy =  cfs.getCompactionStrategyManager();
        List<AbstractCompactionStrategy> strategies = strategy.getStrategies();
        LeveledCompactionStrategy repaired = (LeveledCompactionStrategy) strategies.get(0);
        LeveledCompactionStrategy unrepaired = (LeveledCompactionStrategy) strategies.get(1);
        assertEquals(0, repaired.manifest.getLevelCount() );
        assertEquals(2, unrepaired.manifest.getLevelCount());
        assertTrue(strategy.getSSTableCountPerLevel()[1] > 0);
        assertTrue(strategy.getSSTableCountPerLevel()[2] > 0);

        for (SSTableReader sstable : cfs.getLiveSSTables())
            assertFalse(sstable.isRepaired());

        int sstableCount = 0;
        for (List<SSTableReader> level : unrepaired.manifest.generations)
            sstableCount += level.size();
        // we only have unrepaired sstables:
        assertEquals(sstableCount, cfs.getLiveSSTables().size());

        SSTableReader sstable1 = unrepaired.manifest.generations[2].get(0);
        SSTableReader sstable2 = unrepaired.manifest.generations[1].get(0);

        sstable1.descriptor.getMetadataSerializer().mutateRepairedAt(sstable1.descriptor, System.currentTimeMillis());
        sstable1.reloadSSTableMetadata();
        assertTrue(sstable1.isRepaired());

        strategy.handleNotification(new SSTableRepairStatusChanged(Arrays.asList(sstable1)), this);

        int repairedSSTableCount = 0;
        for (List<SSTableReader> level : repaired.manifest.generations)
            repairedSSTableCount += level.size();
        assertEquals(1, repairedSSTableCount);
        // make sure the repaired sstable ends up in the same level in the repaired manifest:
        assertTrue(repaired.manifest.generations[2].contains(sstable1));
        // and that it is gone from unrepaired
        assertFalse(unrepaired.manifest.generations[2].contains(sstable1));

        unrepaired.removeSSTable(sstable2);
        strategy.handleNotification(new SSTableAddedNotification(sstable2), this);
        assertTrue(unrepaired.manifest.getLevel(1).contains(sstable2));
        assertFalse(repaired.manifest.getLevel(1).contains(sstable2));
    }
}


text:
<?php

$startTime = microtime(true);
$fileDir = dirname(__FILE__);

require($fileDir . '/library/XenForo/Autoloader.php');

XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');

XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

$deps = new XenForo_Dependencies_Public();
$deps->preLoadData();

$response = new Zend_Controller_Response_Http();
$processor = new XenForo_UserUpgradeProcessor_Paymentwall();
$processor->initCallbackHandling(new Zend_Controller_Request_Http());

$logExtra = array();

try {
    if (!($processor->validateRequest() && $processor->validatePreConditions())) {
        throw new Exception($processor->getLogMessage(), 500);
    }

    list($logType, $logMessage) = $processor->processTransaction();

} catch (Exception $e) {
    $response->setHttpResponseCode($e->getCode());
    XenForo_Error::logException($e);

    $logType = 'error';
    $logMessage = 'Exception: ' . $e->getMessage();
    $logExtra['_e'] = $e;
}

$processor->log($logType, $logMessage, $logExtra);

$response->setBody(htmlspecialchars($logMessage));
$response->sendResponse();


text:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package no.oddsor.simulator3.sensor;

import java.awt.Point;

/**
 * A Circle is just a full Cone.
 * @author Odd
 */
class Circle extends Cone{

    public Circle(Point origo, double radian){
        super(origo, 0, new double[]{radian}, 360);
    }
}


text:
<?xml version="1.0" encoding="utf-8"?>
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="600"
    android:propertyName="rotation"
    android:repeatMode="restart"
    android:valueFrom="0"
    android:valueTo="360"
    android:valueType="floatType" />


text:
typedef MKNetworkOperation HttpRequest;
typedef void(^RequestHelper_normalRequestSucceedBlock)(HttpRequest *op);
typedef void(^RequestHelper_normalRequestFailedBlock)(HttpRequest *op, NSError* err);

typedef void(^RequestHelper_downloadRequestSucceedBlock)(HttpRequest *op);
typedef void(^RequestHelper_downloadRequestFailedBlock)(HttpRequest *op, NSError* err);
typedef void(^RequestHelper_downloadRequestProgressBlock)(double progress);

@interface RequestHelper : MKNetworkEngine

typedef enum {
    requestHelper_get = 1,
    requestHelper_post,
    requestHelper_put,
    requestHelper_del,
} HTTPMethod;

@property (nonatomic, assign) BOOL freezable;
@property (nonatomic, assign) BOOL forceReload;
//
+ (id)defaultSettings;

- (HttpRequest *)get:(NSString *)path;
- (HttpRequest *)get:(NSString *)path
              params:(id)anObject;

- (HttpRequest *)post:(NSString *)path
               params:(id)anObject;

- (HttpRequest *)request:(NSString *)path
                  params:(id)anObject
                  method:(HTTPMethod)httpMethod;
// cancel
- (void)cancelRequestWithString:(NSString*)string;

- (id)submit:(HttpRequest *)op;

//////////////////        Image        ////////////////////
#pragma mark- Image
// 设置图片缓存引擎
#define XY_setupWebImageEngine [UIImageView setDefaultEngine:[RequestHelper webImageEngine]];
+ (id)webImageEngine;

// 子类需要重新写, 暂时废弃
//+(NSString *) generateAccessTokenWithObject:(id)anObject;
@end

#pragma mark -  MKNetworkOperation (XY)
@interface MKNetworkOperation (XY)

- (id)uploadFiles:(NSDictionary *)name_path;
- (id)succeed:(RequestHelper_normalRequestSucceedBlock)blockS
       failed:(RequestHelper_normalRequestFailedBlock)blockF;
- (id)submitInQueue:(RequestHelper *)requests;
@end

#pragma mark - download
@class DownloadHelper;
@class Downloader;

@interface Downloader : HttpRequest

@property (nonatomic, copy) NSString *toFile;

- (id)submitInQueue:(DownloadHelper *)requests;
- (id)progress:(RequestHelper_downloadRequestProgressBlock)blockP;

// 请重载此方法实现自己的通用解析方法
- (id)succeed:(RequestHelper_downloadRequestSucceedBlock)blockS
       failed:(RequestHelper_downloadRequestFailedBlock)blockF;
@end

@interface DownloadHelper : MKNetworkEngine
+ (id)defaultSettings;      // 参考

// 下载前,请先执行此方法;
- (void)setup;

- (Downloader *)download:(NSString *)remoteURL
                      to:(NSString*)filePath
                  params:(id)anObject
        breakpointResume:(BOOL)isResume;

- (void)cancelAllDownloads;
- (void)cancelDownloadWithString:(NSString *)string;

- (NSArray *)allDownloads;
- (Downloader *)getADownloadWithString:(NSString *)string;

- (void)emptyTempFile;

- (id)submit:(Downloader *)op;

#pragma mark- todo ,数量控制
// 定义队列最大并发数量, 默认为wifi下 6, 2g/3g下 2
//@property (nonatomic, assign) int maxOperationCount;
@end


text:
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is JavaScript Engine testing utilities.
 *
 * The Initial Developer of the Original Code is
 * Mozilla Foundation.
 * Portions created by the Initial Developer are Copyright (C) 2006
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s): nanto vi (TOYAMA Nao)
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

var gTestfile = 'regress-348685.js';
//-----------------------------------------------------------------------------
var BUGNUMBER = 348685;
var summary = 'Let scoped variables should not be referenced outside blocks';
var actual = '';
var expect = '';

//-----------------------------------------------------------------------------
test();
//-----------------------------------------------------------------------------

function test()
{
  enterFunc ('test');
  printBugNumber(BUGNUMBER);
  printStatus (summary);

  function f() {
    for (let i = 0; i < 2; i++) {
      let j = 42;
      function g() {}
    }
    var a = i;
    print(a);
    print(i);
    return i;
  }

  expect = /ReferenceError: (i|"i") is not defined/;

  try
  {
    f();
  }
  catch(ex)
  {
    actual = ex + '';
  }
  reportMatch(expect, actual, summary);

  exitFunc ('test');
}


text:
title: Themes
permalink: /docs/themes/
---

Jekyll has an extensive theme system that allows you to leverage community-maintained templates and styles to customize your site's presentation. Jekyll themes specify plugins and package up assets, layouts, includes, and stylesheets in a way that can be overridden by your site's content.

## Pick up a theme

You can find and preview themes on different galleries:

- [jamstackthemes.dev](https://jamstackthemes.dev/ssg/jekyll/)
- [jekyllthemes.org](http://jekyllthemes.org/)
- [jekyllthemes.io](https://jekyllthemes.io/)
- [jekyll-themes.com](https://jekyll-themes.com/)

## Understanding gem-based themes

When you [create a new Jekyll site](/docs/) (by running the `jekyll new <PATH>` command), Jekyll installs a site that uses a gem-based theme called [Minima](https://github.com/jekyll/minima).

With gem-based themes, some of the site's directories (such as the `assets`, `_layouts`, `_includes`, and `_sass` directories) are stored in the theme's gem, hidden from your immediate view. Yet all of the necessary directories will be read and processed during Jekyll's build process.

In the case of Minima, you see only the following files in your Jekyll site directory:

```
.
├── Gemfile
├── Gemfile.lock
├── _config.yml
├── _posts
│   └── 2016-12-04-welcome-to-jekyll.markdown
├── about.markdown
└── index.markdown
```

The `Gemfile` and `Gemfile.lock` files are used by Bundler to keep track of the required gems and gem versions you need to build your Jekyll site.

Gem-based themes make it easier for theme developers to make updates available to anyone who has the theme gem. When there's an update, theme developers push the update to RubyGems.

If you have the theme gem, you can (if you desire) run `bundle update` to update all gems in your project. Or you can run `bundle update <THEME>`, replacing `<THEME>` with the theme name, such as `minima`, to just update the theme gem. Any new files or updates the theme developer has made (such as to stylesheets or includes) will be pulled into your project automatically.

The goal of gem-based themes is to allow you to get all the benefits of a robust, continually updated theme without having all the theme's files getting in your way and over-complicating what might be your primary focus: creating content.

## Overriding theme defaults

Jekyll themes set default layouts, includes, and stylesheets. However, you can override any of the theme defaults with your own site content.

To replace layouts or includes in your theme, make a copy in your `_layouts` or `_includes` directory of the specific file you wish to modify, or create the file from scratch giving it the same name as the file you wish to override.

For example, if your selected theme has a `page` layout, you can override the theme's layout by creating your own `page` layout in the `_layouts` directory (that is, `_layouts/page.html`).

To locate a theme's files on your computer:

1. Run `bundle info --path` followed by the name of the theme's gem, e.g., `bundle info --path minima` for Jekyll's default theme.

   This returns the location of the gem-based theme files. For example, the Minima theme's files might be located in `/usr/local/lib/ruby/gems/2.6.0/gems/minima-2.5.1` on macOS.

2. Open the theme's directory in Finder or Explorer:

   ```sh
   # On MacOS
   open $(bundle info --path minima)

   # On Windows
   # First get the gem's installation path:
   #
   #   bundle info --path minima
   #   => C:/Ruby26-x64/lib/ruby/gems/{{ site.data.ruby.current_version }}/gems/minima-2.5.1
   #
   # then invoke explorer with above path, substituting `/` with `\`
   explorer C:\Ruby26-x64\lib\ruby\gems\{{ site.data.ruby.current_version}}\gems\minima-2.5.1

   # On Linux
   xdg-open $(bundle info --path minima)
   ```

   A Finder or Explorer window opens showing the theme's files and directories. The Minima theme gem contains these files:

   ```
   .
   ├── LICENSE.txt
   ├── README.md
   ├── _includes
   │   ├── disqus_comments.html
   │   ├── footer.html
   │   ├── google-analytics.html
   │   ├── head.html
   │   ├── header.html
   │   ├── icon-github.html
   │   ├── icon-github.svg
   │   ├── icon-twitter.html
   │   └── icon-twitter.svg
   ├── _layouts
   │   ├── default.html
   │   ├── home.html
   │   ├── page.html
   │   └── post.html
   ├── _sass
   │   ├── minima
   │   │   ├── _base.scss
   │   │   ├── _layout.scss
   │   │   └── _syntax-highlighting.scss
   │   └── minima.scss
   └── assets
       └── main.scss
   ```

With a clear understanding of the theme's files, you can now override any theme file by creating a similarly named file in your Jekyll site directory.

Let's say, for a second example, you want to override Minima's footer. In your Jekyll site, create an `_includes` folder and add a file in it called `footer.html`. Jekyll will now use your site's `footer.html` file instead of the `footer.html` file from the Minima theme gem.

To modify any stylesheet you must take the extra step of also copying the main sass file (`_sass/minima.scss` in the Minima theme) into the `_sass` directory in your site's source.

Jekyll will look first to your site's content before looking to the theme's defaults for any requested file in the following folders:

- `/assets`
- `/_layouts`
- `/_includes`
- `/_sass`

Note that making copies of theme files will prevent you from receiving any theme updates on those files. An alternative, to continue getting theme updates on all stylesheets, is to use higher specificity CSS selectors in your own additional, originally named CSS files.

{: .note .info}
Refer to your selected theme's documentation and source repository for more information on which files you can override.

## Converting gem-based themes to regular themes

Suppose you want to get rid of the gem-based theme and convert it to a regular theme, where all files are present in your Jekyll site directory, with nothing stored in the theme gem.

To do this, copy the files from the theme gem's directory into your Jekyll site directory. (For example, copy them to `/myblog` if you created your Jekyll site at `/myblog`. See the previous section for details.)

Then you must tell Jekyll about the plugins that were referenced by the theme. You can find these plugins in the theme's gemspec file as runtime dependencies. If you were converting the Minima theme, for example, you might see:

```ruby
spec.add_runtime_dependency "jekyll-feed", "~> 0.12"
spec.add_runtime_dependency "jekyll-seo-tag", "~> 2.6"
```

You should include these references in the `Gemfile` in one of two ways.

You could list them individually in both `Gemfile` and `_config.yml`.

```ruby
# ./Gemfile

gem "jekyll-feed", "~> 0.12"
gem "jekyll-seo-tag", "~> 2.6"
```

```yaml
# ./_config.yml

plugins:
  - jekyll-feed
  - jekyll-seo-tag
```

Or you could list them explicitly as Jekyll plugins in your Gemfile, and not update `_config.yml`, like this:

```ruby
# ./Gemfile

group :jekyll_plugins do
  gem "jekyll-feed", "~> 0.12"
  gem "jekyll-seo-tag", "~> 2.6"
end
```

Either way, don't forget to `bundle update`.

If you're publishing on GitHub Pages you should update only your `_config.yml` as GitHub Pages doesn't load plugins via Bundler.

Finally, remove references to the theme gem in `Gemfile` and configuration. For example, to remove `minima`:

- Open `Gemfile` and remove `gem "minima", "~> 2.5"`.
- Open `_config.yml` and remove `theme: minima`.

Now `bundle update` will no longer get updates for the theme gem.

## Installing a gem-based theme {#installing-a-theme}

The `jekyll new <PATH>` command isn't the only way to create a new Jekyll site with a gem-based theme. You can also find gem-based themes online and incorporate them into your Jekyll project.

For example, search for [jekyll theme on RubyGems](https://rubygems.org/search?utf8=%E2%9C%93&query=jekyll-theme) to find other gem-based themes. (Note that not all themes are using `jekyll-theme` as a convention in the theme name.)

To install a gem-based theme:

1. Add the theme gem to your site's `Gemfile`:

   ```ruby
   # ./Gemfile

   # This is an example, declare the theme gem you want to use here
   gem "jekyll-theme-minimal"
   ```

   Or if you've started with the `jekyll new` command, replace `gem "minima", "~> 2.0"` with the gem you want, e.g:

   ```diff
   # ./Gemfile

   - gem "minima", "~> 2.5"
   + gem "jekyll-theme-minimal"
   ```

2. Install the theme:

   ```sh
   bundle install
   ```

3. Add the following to your site's `_config.yml` to activate the theme:

   ```yaml
   theme: jekyll-theme-minimal
   ```

4. Build your site:

   ```sh
   bundle exec jekyll serve
   ```

{: .note .info}
You can have multiple themes listed in your site's `Gemfile`, but only one theme can be selected in your site's `_config.yml`.

If you're publishing your Jekyll site on [GitHub Pages](https://pages.github.com/), note that GitHub Pages supports only [some gem-based themes](https://pages.github.com/themes/). GitHub Pages also supports [using any theme hosted on GitHub](https://help.github.com/articles/adding-a-jekyll-theme-to-your-github-pages-site/#adding-a-jekyll-theme-in-your-sites-_configyml-file) using the `remote_theme` configuration as if it were a gem-based theme.

## Creating a gem-based theme

If you're a Jekyll theme developer (rather than a consumer of themes), you can package up your theme in RubyGems and allow users to install it through Bundler.

If you're unfamiliar with creating Ruby gems, don't worry. Jekyll will help you scaffold a new theme with the `new-theme` command. Run `jekyll new-theme` with the theme name as an argument.

Here is an example:

```sh
jekyll new-theme jekyll-theme-awesome
    create /path/to/jekyll-theme-awesome/_layouts
    create /path/to/jekyll-theme-awesome/_includes
    create /path/to/jekyll-theme-awesome/_sass
    create /path/to/jekyll-theme-awesome/_layouts/page.html
    create /path/to/jekyll-theme-awesome/_layouts/post.html
    create /path/to/jekyll-theme-awesome/_layouts/default.html
    create /path/to/jekyll-theme-awesome/Gemfile
    create /path/to/jekyll-theme-awesome/jekyll-theme-awesome.gemspec
    create /path/to/jekyll-theme-awesome/README.md
    create /path/to/jekyll-theme-awesome/LICENSE.txt
    initialize /path/to/jekyll-theme-awesome/.git
    create /path/to/jekyll-theme-awesome/.gitignore
Your new Jekyll theme, jekyll-theme-awesome, is ready for you in /path/to/jekyll-theme-awesome!
For help getting started, read /path/to/jekyll-theme-awesome/README.md.
```

Add your template files in the corresponding folders. Then complete the `.gemspec` and the README files according to your needs.

### Layouts and includes

Theme layouts and includes work just like they work in any Jekyll site. Place layouts in your theme's `/_layouts` folder, and place includes in your themes `/_includes` folder.

For example, if your theme has a `/_layouts/page.html` file, and a page has `layout: page` in its front matter, Jekyll will first look to the site's `_layouts` folder for the `page` layout, and if none exists, will use your theme's `page` layout.

### Assets

Any file in `/assets` will be copied over to the user's site upon build unless they have a file with the same relative path. You can ship any kind of asset here: SCSS, an image, a webfont, etc. These files behave like pages and static files in Jekyll:

- If the file has [front matter](/docs/front-matter/) at the top, it will be rendered.
- If the file does not have front matter, it will simply be copied over into the resulting site.

This allows theme creators to ship a default `/assets/styles.scss` file which their layouts can depend on as `/assets/styles.css`.

All files in `/assets` will be output into the compiled site in the `/assets` folder just as you'd expect from using Jekyll on your sites.

### Stylesheets

Your theme's stylesheets should be placed in your theme's `_sass` folder, again, just as you would when authoring a Jekyll site.

```
_sass
└── jekyll-theme-awesome.scss
```

Your theme's styles can be included in the user's stylesheet using the `@import` directive.

{% raw %}
```css
@import "{{ site.theme }}";
```
{% endraw %}

### Theme-gem dependencies {%- include docs_version_badge.html version="3.5.0" -%}

Jekyll will automatically require all whitelisted `runtime_dependencies` of your theme-gem even if they're not explicitly included under the `plugins` array in the site's config file. (Note: whitelisting is only required when building or serving with the `--safe` option.)

With this, the end-user need not keep track of the plugins required to be included in their config file for their theme-gem to work as intended.

### Pre-configuring Theme-gems {%- include docs_version_badge.html version="4.0" -%}

Jekyll will read-in a `_config.yml` at the root of the theme-gem and merge its data into the site's existing configuration data.

But unlike other entities loaded from within the theme, loading the config file comes with a few restrictions, as summarized below:
  * Jekyll's default settings cannot be overridden by a theme-config. That *ball is still in the user's court.*
  * The theme-config-file cannot be a symlink, irrespective of `safe mode` and whether the file pointed to by the symlink is a legitimate file within the theme-gem.
  * The theme-config should be a set of key-value pairs. An empty config file, a config file that simply *lists items* under a key, or a config file with just a simple string of text will simply be ignored silently. Users will not get a warning or any log output regarding this discrepancy.
  * Any settings defined by the theme-config can be overridden by the user.

While this feature is to enable easier adoption of a theme, the restrictions ensure that a theme-config cannot affect the build in a concerning manner. Any plugins required by the theme will have to be listed manually by the user or provided by the theme's `gemspec` file.

This feature will let the theme-gem to work with *theme-specific config variables* out-of-the-box.

### Documenting your theme

Your theme should include a `/README.md` file, which explains how site authors can install and use your theme. What layouts are included? What includes? Do they need to add anything special to their site's configuration file?

### Adding a screenshot

Themes are visual. Show users what your theme looks like by including a screenshot as `/screenshot.png` within your theme's repository where it can be retrieved programmatically. You can also include this screenshot within your theme's documentation.

### Previewing your theme

To preview your theme as you're authoring it, it may be helpful to add dummy content in, for example, `/index.html` and `/page.html` files. This will allow you to use the `jekyll build` and `jekyll serve` commands to preview your theme, just as you'd preview a Jekyll site.

{: .note .info}
If you do preview your theme locally, be sure to add `/_site` to your theme's `.gitignore` file to prevent the compiled site from also being included when you distribute your theme.

### Publishing your theme

Themes are published via [RubyGems.org](https://rubygems.org). You will need a RubyGems account, which you can [create for free](https://rubygems.org/sign_up).

1. First, you need to have it in a git repository:

   ```sh
   git init # Only the first time
   git add -A
   git commit -m "Init commit"
   ```

2. Next, package your theme, by running the following command, replacing `jekyll-theme-awesome` with the name of your theme:

   ```sh
   gem build jekyll-theme-awesome.gemspec
   ```

3. Finally, push your packaged theme up to the RubyGems service, by running the following command, again replacing `jekyll-theme-awesome` with the name of your theme:

   ```sh
   gem push jekyll-theme-awesome-*.gem
   ```

4. To release a new version of your theme, update the version number in the gemspec file, ( `jekyll-theme-awesome.gemspec` in this example ), and then repeat Steps 1 - 3 above. We recommend that you follow [Semantic Versioning](http://semver.org/) while bumping your theme-version.


text:
subreddit = 'EDC'
t_channel = '@r_edc'

def send_post(submission, r2t):
    return r2t.send_simple(submission)


text:
@interface ManualServerWindow : NSWindowController <ReceiveServerDelegate> {
    id<ManualServerWindowDelegate> delegate;
}

@property (nonatomic, retain) id<ManualServerWindowDelegate> delegate;

@end


text:
import React from 'react'
import ReactDom, {render} from 'react-dom'

require('../index.js');

require('./demo.less');

class Main extends React.Component {
    onTap(index) {
        alert(index);
    }
    render () {
        return (

Tap

this.onTap(1)} tapActive={true}>tap1

this.onTap(2)} tapActive={'tap-ripple'}>tap2

this.onTap(3)} tapActive={'green'}>tap3

        )
    }
}

render(, document.getElementById('container'));


text:
var vows   = require('vows');
var assert = require('assert');

require('../lib/date-utils.js');

vows.describe('Date New').addBatch({
    'can return a new object from today static method': {
        topic: function () { return Date.today(); },
        'returns the correct time': function (date) {
            var compare = new Date().clearTime();
            assert.equal(date.valueOf(), compare.valueOf());
        }
    },

    'clearTime() works': {
        topic: function() { return new Date().clearTime(); },
        'returns the correct value': function (date) {
            var compare = new Date();
            compare.setHours(0);
            compare.setMinutes(0);
            compare.setSeconds(0);
            compare.setMilliseconds(0);

            assert.equal(date.valueOf(), compare.valueOf());
        }
    },

    'clearUTCTime() works': {
        topic: function() { return new Date().clearUTCTime(); },
        'returns the correct value': function (date) {
            var compare = new Date();
            compare.setUTCHours(0);
            compare.setUTCMinutes(0);
            compare.setUTCSeconds(0);
            compare.setUTCMilliseconds(0);

            assert.equal(date.valueOf(), compare.valueOf());
        }
    },

    'today() works': {
        topic: function() {
            return Date.today();
        },
        'returns the correct value': function(date) {
            var compare = new Date().clearTime();
            assert.equal(date.valueOf(), compare.valueOf());
        }
    },

    'UTCtoday() works': {
        topic: function() {
            return Date.UTCtoday();
        },
        'returns the correct value': function(date) {
            var compare = new Date().clearUTCTime();
            assert.equal(date.valueOf(), compare.valueOf());
        }
    },

    'yesterday() works': {
        topic: function() {
            return Date.yesterday();
        },
        'returns the correct value': function(date) {
            var compare = new Date().clearTime();
            compare.setSeconds(compare.getSeconds() - 86400);
            assert.equal(date.valueOf(), compare.valueOf());
        }
    },

    'UTCyesterday() works': {
        topic: function() {
            return Date.UTCyesterday();
        },
        'returns the correct value': function(date) {
            var compare = new Date().clearUTCTime();
            compare.setSeconds(compare.getSeconds() - 86400);
            assert.equal(date.valueOf(), compare.valueOf());
        }
    },

    'tomorrow() works': {
        topic: function() {
            return Date.tomorrow();
        },
        'returns the correct value': function(date) {
            var compare = new Date().clearTime();
            compare.setSeconds(compare.getSeconds() + 86400);
            assert.equal(date.valueOf(), compare.valueOf());
        }
    },

    'UTCtomorrow() works': {
        topic: function() {
            return Date.UTCtomorrow();
        },
        'returns the correct value': function(date) {
            var compare = new Date().clearUTCTime();
            compare.setSeconds(compare.getSeconds() + 86400);
            assert.equal(date.valueOf(), compare.valueOf());
        }
    }

}).export(module);


text:
package kantan.codecs.shapeless.laws

sealed trait Or[+A, +B]         extends Product with Serializable
final case class Left[A](a: A)  extends Or[A, Nothing]
final case class Right[B](b: B) extends Or[Nothing, B]


text:
$('main').on('click', '.remove', function () {
    return confirm('Вы уверены, что хотите удалить?');
});


text:
//
//  OMCCore.h
//  OMCCore
//
//  Copyright (c) 2015, Oracle Corp. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

/**
 Defines the version constant for the Core library.
 */
@interface OMCCore : NSObject

@end

/**
 The Core library's current version.
 */
extern NSString* const OMCCoreVersion;

/**
 Completion handler used when reporting an optional error.
 */
typedef void (^OMCErrorCompletionBlock)(NSError* _Nullable error);

NS_ASSUME_NONNULL_END


text:
namespace inet {

// nothing to see here, please move along

} // namespace inet


text:
/**
 * Created by Doron Sinai on 16/10/2014.
 */
angular.module('MyApp')
    .factory('Episode', ['$resource', function($resource) {
        return $resource('/api/episodes/:_id');
    }]);