text:
package org.apache.samza.container.grouper.task;

import org.apache.samza.SamzaException;
import org.apache.samza.container.LocalityManager;
import org.apache.samza.job.model.ContainerModel;
import org.apache.samza.job.model.TaskModel;
import org.junit.Before;
import org.junit.Test;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import static org.apache.samza.container.mock.ContainerMocks.generateTaskContainerMapping;
import static org.apache.samza.container.mock.ContainerMocks.generateTaskModels;
import static org.apache.samza.container.mock.ContainerMocks.getTaskModel;
import static org.apache.samza.container.mock.ContainerMocks.getTaskName;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyCollection;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

public class TestGroupByContainerCount {
  private TaskAssignmentManager taskAssignmentManager;
  private LocalityManager localityManager;
  @Before
  public void setup() {
    taskAssignmentManager = mock(TaskAssignmentManager.class);
    localityManager = mock(LocalityManager.class);
    when(localityManager.getTaskAssignmentManager()).thenReturn(taskAssignmentManager);
  }

  @Test(expected = IllegalArgumentException.class)
  public void testGroupEmptyTasks() {
    new GroupByContainerCount(1).group(new HashSet());
  }

  @Test(expected = IllegalArgumentException.class)
  public void testGroupFewerTasksThanContainers() {
    Set<TaskModel> taskModels = new HashSet<>();
    taskModels.add(getTaskModel(1));
    new GroupByContainerCount(2).group(taskModels);
  }

  @Test(expected = UnsupportedOperationException.class)
  public void testGrouperResultImmutable() {
    Set<TaskModel> taskModels = generateTaskModels(3);
    Set<ContainerModel> containers = new GroupByContainerCount(3).group(taskModels);
    containers.remove(containers.iterator().next());
  }

  @Test
  public void testGroupHappyPath() {
    Set<TaskModel> taskModels = generateTaskModels(5);

    Set<ContainerModel> containers = new GroupByContainerCount(2).group(taskModels);

    Map<String, ContainerModel> containersMap = new HashMap<>();
    for (ContainerModel container : containers) {
      containersMap.put(container.getProcessorId(), container);
    }

    assertEquals(2, containers.size());
    ContainerModel container0 = containersMap.get("0");
    ContainerModel container1 = containersMap.get("1");
    assertNotNull(container0);
    assertNotNull(container1);
    assertEquals("0", container0.getProcessorId());
    assertEquals("1", container1.getProcessorId());
    assertEquals(3, container0.getTasks().size());
    assertEquals(2, container1.getTasks().size());
    assertTrue(container0.getTasks().containsKey(getTaskName(0)));
    assertTrue(container0.getTasks().containsKey(getTaskName(2)));
    assertTrue(container0.getTasks().containsKey(getTaskName(4)));
    assertTrue(container1.getTasks().containsKey(getTaskName(1)));
    assertTrue(container1.getTasks().containsKey(getTaskName(3)));
  }

  @Test
  public void testGroupManyTasks() {
    Set<TaskModel> taskModels = generateTaskModels(21);

    Set<ContainerModel> containers = new GroupByContainerCount(2).group(taskModels);

    Map<String, ContainerModel> containersMap = new HashMap<>();
    for (ContainerModel container : containers) {
      containersMap.put(container.getProcessorId(), container);
    }

    assertEquals(2, containers.size());
    ContainerModel container0 = containersMap.get("0");
    ContainerModel container1 = containersMap.get("1");
    assertNotNull(container0);
    assertNotNull(container1);
    assertEquals("0", container0.getProcessorId());
    assertEquals("1", container1.getProcessorId());
    assertEquals(11, container0.getTasks().size());
    assertEquals(10, container1.getTasks().size());

    // NOTE: tasks are sorted lexicographically, so the container assignment
    // can seem odd, but the consistency is the key focus
    assertTrue(container0.getTasks().containsKey(getTaskName(0)));
    assertTrue(container0.getTasks().containsKey(getTaskName(10)));
    assertTrue(container0.getTasks().containsKey(getTaskName(12)));
    assertTrue(container0.getTasks().containsKey(getTaskName(14)));
    assertTrue(container0.getTasks().containsKey(getTaskName(16)));
    assertTrue(container0.getTasks().containsKey(getTaskName(18)));
    assertTrue(container0.getTasks().containsKey(getTaskName(2)));
    assertTrue(container0.getTasks().containsKey(getTaskName(3)));
    assertTrue(container0.getTasks().containsKey(getTaskName(5)));
    assertTrue(container0.getTasks().containsKey(getTaskName(7)));
    assertTrue(container0.getTasks().containsKey(getTaskName(9)));

    assertTrue(container1.getTasks().containsKey(getTaskName(1)));
    assertTrue(container1.getTasks().containsKey(getTaskName(11)));
    assertTrue(container1.getTasks().containsKey(getTaskName(13)));
    assertTrue(container1.getTasks().containsKey(getTaskName(15)));
    assertTrue(container1.getTasks().containsKey(getTaskName(17)));
    assertTrue(container1.getTasks().containsKey(getTaskName(19)));
    assertTrue(container1.getTasks().containsKey(getTaskName(20)));
    assertTrue(container1.getTasks().containsKey(getTaskName(4)));
    assertTrue(container1.getTasks().containsKey(getTaskName(6)));
    assertTrue(container1.getTasks().containsKey(getTaskName(8)));
  }

  /**
   * Before:
   *  C0  C1
   * --------
   *  T0  T1
   *  T2  T3
   *  T4  T5
   *  T6  T7
   *  T8
   *
   * After:
   *  C0  C1  C2  C3
   * ----------------
   *  T0  T1  T6  T5
   *  T2  T3  T8  T7
   *  T4
   *
   *  NOTE for host affinity, it would help to have some additional logic to reassign tasks
   *  from C0 and C1 to containers that were on the same respective hosts, it wasn't implemented
   *  because the scenario is infrequent, the benefits are not guaranteed, and the code complexity
   *  wasn't worth it. It certainly could be implemented in the future.
   */
  @Test
  public void testBalancerAfterContainerIncrease() {
    Set<TaskModel> taskModels = generateTaskModels(9);
    Set<ContainerModel> prevContainers = new GroupByContainerCount(2).group(taskModels);
    Map<String, String> prevTaskToContainerMapping = generateTaskContainerMapping(prevContainers);
    when(taskAssignmentManager.readTaskAssignment()).thenReturn(prevTaskToContainerMapping);

    Set<ContainerModel> containers = new GroupByContainerCount(4).balance(taskModels, localityManager);

    Map<String, ContainerModel> containersMap = new HashMap<>();
    for (ContainerModel container : containers) {
      containersMap.put(container.getProcessorId(), container);
    }

    assertEquals(4, containers.size());
    ContainerModel container0 = containersMap.get("0");
    ContainerModel container1 = containersMap.get("1");
    ContainerModel container2 = containersMap.get("2");
    ContainerModel container3 = containersMap.get("3");
    assertNotNull(container0);
    assertNotNull(container1);
    assertNotNull(container2);
    assertNotNull(container3);
    assertEquals("0", container0.getProcessorId());
    assertEquals("1", container1.getProcessorId());
    assertEquals(3, container0.getTasks().size());
    assertEquals(2, container1.getTasks().size());
    assertEquals(2, container2.getTasks().size());
    assertEquals(2, container3.getTasks().size());

    // Tasks 0-4 should stay on the same original containers
    assertTrue(container0.getTasks().containsKey(getTaskName(0)));
    assertTrue(container0.getTasks().containsKey(getTaskName(2)));
    assertTrue(container0.getTasks().containsKey(getTaskName(4)));
    assertTrue(container1.getTasks().containsKey(getTaskName(1)));
    assertTrue(container1.getTasks().containsKey(getTaskName(3)));
    // Tasks 5-8 should be reassigned to the new containers.
    // Consistency is the goal with these reassignments
    assertTrue(container2.getTasks().containsKey(getTaskName(8)));
    assertTrue(container2.getTasks().containsKey(getTaskName(6)));
    assertTrue(container3.getTasks().containsKey(getTaskName(5)));
    assertTrue(container3.getTasks().containsKey(getTaskName(7)));

    // Verify task mappings are saved
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(0).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(2).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(4).getTaskName(), "0");

    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(1).getTaskName(), "1");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(3).getTaskName(), "1");

    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(8).getTaskName(), "2");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(6).getTaskName(), "2");

    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(5).getTaskName(), "3");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(7).getTaskName(), "3");

    verify(taskAssignmentManager, never()).deleteTaskContainerMappings(anyCollection());
  }

  /**
   * Before:
   *  C0  C1  C2  C3
   * ----------------
   *  T0  T1  T2  T3
   *  T4  T5  T6  T7
   *  T8
   *
   * After:
   *  C0  C1
   * --------
   *  T0  T1
   *  T4  T5
   *  T8  T7
   *  T6  T3
   *  T2
   *
   *  NOTE for host affinity, it would help to have some additional logic to reassign tasks
   *  from C2 and C3 to containers that were on the same respective hosts, it wasn't implemented
   *  because the scenario is infrequent, the benefits are not guaranteed, and the code complexity
   *  wasn't worth it. It certainly could be implemented in the future.
   */
  @Test
  public void testBalancerAfterContainerDecrease() {
    Set<TaskModel> taskModels = generateTaskModels(9);
    Set<ContainerModel> prevContainers = new GroupByContainerCount(4).group(taskModels);
    Map<String, String> prevTaskToContainerMapping = generateTaskContainerMapping(prevContainers);
    when(taskAssignmentManager.readTaskAssignment()).thenReturn(prevTaskToContainerMapping);

    Set<ContainerModel> containers = new GroupByContainerCount(2).balance(taskModels, localityManager);

    Map<String, ContainerModel> containersMap = new HashMap<>();
    for (ContainerModel container : containers) {
      containersMap.put(container.getProcessorId(), container);
    }

    assertEquals(2, containers.size());
    ContainerModel container0 = containersMap.get("0");
    ContainerModel container1 = containersMap.get("1");
    assertNotNull(container0);
    assertNotNull(container1);
    assertEquals("0", container0.getProcessorId());
    assertEquals("1", container1.getProcessorId());
    assertEquals(5, container0.getTasks().size());
    assertEquals(4, container1.getTasks().size());

    // Tasks 0,4,8 and 1,5 should stay on the same original containers
    assertTrue(container0.getTasks().containsKey(getTaskName(0)));
    assertTrue(container0.getTasks().containsKey(getTaskName(4)));
    assertTrue(container0.getTasks().containsKey(getTaskName(8)));
    assertTrue(container1.getTasks().containsKey(getTaskName(1)));
    assertTrue(container1.getTasks().containsKey(getTaskName(5)));

    // Tasks 2,6 and 3,7 should be reassigned to the new containers.
    // Consistency is the goal with these reassignments
    assertTrue(container0.getTasks().containsKey(getTaskName(6)));
    assertTrue(container0.getTasks().containsKey(getTaskName(2)));
    assertTrue(container1.getTasks().containsKey(getTaskName(7)));
    assertTrue(container1.getTasks().containsKey(getTaskName(3)));

    // Verify task mappings are saved
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(0).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(4).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(8).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(6).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(2).getTaskName(), "0");

    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(1).getTaskName(), "1");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(5).getTaskName(), "1");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(7).getTaskName(), "1");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(3).getTaskName(), "1");

    verify(taskAssignmentManager, never()).deleteTaskContainerMappings(anyCollection());
  }

  /**
   * Before:
   *  C0  C1  C2  C3
   * ----------------
   *  T0  T1  T2  T3
   *  T4  T5  T6  T7
   *  T8
   *
   * Intermediate:
   *  C0  C1
   * --------
   *  T0  T1
   *  T4  T5
   *  T8  T7
   *  T6  T3
   *  T2
   *
   *  After:
   *  C0  C1  C2
   * ------------
   *  T0  T1  T6
   *  T4  T5  T2
   *  T8  T7  T3
   */
  @Test
  public void testBalancerMultipleReblances() {
    // Before
    Set<TaskModel> taskModels = generateTaskModels(9);
    Set<ContainerModel> prevContainers = new GroupByContainerCount(4).group(taskModels);
    Map<String, String> prevTaskToContainerMapping = generateTaskContainerMapping(prevContainers);
    when(taskAssignmentManager.readTaskAssignment()).thenReturn(prevTaskToContainerMapping);

    // First balance
    Set<ContainerModel> containers = new GroupByContainerCount(2).balance(taskModels, localityManager);

    Map<String, ContainerModel> containersMap = new HashMap<>();
    for (ContainerModel container : containers) {
      containersMap.put(container.getProcessorId(), container);
    }

    assertEquals(2, containers.size());
    ContainerModel container0 = containersMap.get("0");
    ContainerModel container1 = containersMap.get("1");
    assertNotNull(container0);
    assertNotNull(container1);
    assertEquals("0", container0.getProcessorId());
    assertEquals("1", container1.getProcessorId());
    assertEquals(5, container0.getTasks().size());
    assertEquals(4, container1.getTasks().size());

    // Tasks 0,4,8 and 1,5 should stay on the same original containers
    assertTrue(container0.getTasks().containsKey(getTaskName(0)));
    assertTrue(container0.getTasks().containsKey(getTaskName(4)));
    assertTrue(container0.getTasks().containsKey(getTaskName(8)));
    assertTrue(container1.getTasks().containsKey(getTaskName(1)));
    assertTrue(container1.getTasks().containsKey(getTaskName(5)));

    // Tasks 2,6 and 3,7 should be reassigned to the new containers.
    // Consistency is the goal with these reassignments
    assertTrue(container0.getTasks().containsKey(getTaskName(6)));
    assertTrue(container0.getTasks().containsKey(getTaskName(2)));
    assertTrue(container1.getTasks().containsKey(getTaskName(7)));
    assertTrue(container1.getTasks().containsKey(getTaskName(3)));

    // Verify task mappings are saved
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(0).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(4).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(8).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(6).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(2).getTaskName(), "0");

    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(1).getTaskName(), "1");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(5).getTaskName(), "1");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(7).getTaskName(), "1");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(3).getTaskName(), "1");

    verify(taskAssignmentManager, never()).deleteTaskContainerMappings(anyCollection());

    // Second balance
    prevTaskToContainerMapping = generateTaskContainerMapping(prevContainers);

    TaskAssignmentManager taskAssignmentManager2 = mock(TaskAssignmentManager.class);
    when(taskAssignmentManager2.readTaskAssignment()).thenReturn(prevTaskToContainerMapping);
    LocalityManager localityManager2 = mock(LocalityManager.class);
    when(localityManager2.getTaskAssignmentManager()).thenReturn(taskAssignmentManager2);

    containers = new GroupByContainerCount(3).balance(taskModels, localityManager2);

    containersMap = new HashMap<>();
    for (ContainerModel container : containers) {
      containersMap.put(container.getProcessorId(), container);
    }

    assertEquals(3, containers.size());
    container0 = containersMap.get("0");
    container1 = containersMap.get("1");
    ContainerModel container2 = containersMap.get("2");
    assertNotNull(container0);
    assertNotNull(container1);
    assertNotNull(container2);
    assertEquals("0", container0.getProcessorId());
    assertEquals("1", container1.getProcessorId());
    assertEquals("2", container2.getProcessorId());
    assertEquals(3, container0.getTasks().size());
    assertEquals(3, container1.getTasks().size());
    assertEquals(3, container2.getTasks().size());

    // Tasks 0,4,8 and 1,5,7 should stay on the same original containers
    assertTrue(container0.getTasks().containsKey(getTaskName(0)));
    assertTrue(container0.getTasks().containsKey(getTaskName(4)));
    assertTrue(container0.getTasks().containsKey(getTaskName(8)));
    assertTrue(container1.getTasks().containsKey(getTaskName(1)));
    assertTrue(container1.getTasks().containsKey(getTaskName(5)));
    assertTrue(container1.getTasks().containsKey(getTaskName(7)));

    // Tasks 2,6 and 3 should be reassigned to the new container.
    // Consistency is the goal with these reassignments
    assertTrue(container2.getTasks().containsKey(getTaskName(6)));
    assertTrue(container2.getTasks().containsKey(getTaskName(2)));
    assertTrue(container2.getTasks().containsKey(getTaskName(3)));

    // Verify task mappings are saved
    verify(taskAssignmentManager2).writeTaskContainerMapping(getTaskName(0).getTaskName(), "0");
    verify(taskAssignmentManager2).writeTaskContainerMapping(getTaskName(4).getTaskName(), "0");
    verify(taskAssignmentManager2).writeTaskContainerMapping(getTaskName(8).getTaskName(), "0");

    verify(taskAssignmentManager2).writeTaskContainerMapping(getTaskName(1).getTaskName(), "1");
    verify(taskAssignmentManager2).writeTaskContainerMapping(getTaskName(5).getTaskName(), "1");
    verify(taskAssignmentManager2).writeTaskContainerMapping(getTaskName(7).getTaskName(), "1");

    verify(taskAssignmentManager2).writeTaskContainerMapping(getTaskName(6).getTaskName(), "2");
    verify(taskAssignmentManager2).writeTaskContainerMapping(getTaskName(2).getTaskName(), "2");
    verify(taskAssignmentManager2).writeTaskContainerMapping(getTaskName(3).getTaskName(), "2");

    verify(taskAssignmentManager2, never()).deleteTaskContainerMappings(anyCollection());
  }

  /**
   * Before:
   *  C0  C1
   * --------
   *  T0  T1
   *  T2  T3
   *  T4  T5
   *  T6  T7
   *  T8
   *
   *  After:
   *  C0  C1
   * --------
   *  T0  T1
   *  T2  T3
   *  T4  T5
   *  T6  T7
   *  T8
   */
  @Test
  public void testBalancerAfterContainerSame() {
    Set<TaskModel> taskModels = generateTaskModels(9);
    Set<ContainerModel> prevContainers = new GroupByContainerCount(2).group(taskModels);
    Map<String, String> prevTaskToContainerMapping = generateTaskContainerMapping(prevContainers);
    when(taskAssignmentManager.readTaskAssignment()).thenReturn(prevTaskToContainerMapping);

    Set<ContainerModel> containers = new GroupByContainerCount(2).balance(taskModels, localityManager);

    Map<String, ContainerModel> containersMap = new HashMap<>();
    for (ContainerModel container : containers) {
      containersMap.put(container.getProcessorId(), container);
    }

    assertEquals(2, containers.size());
    ContainerModel container0 = containersMap.get("0");
    ContainerModel container1 = containersMap.get("1");
    assertNotNull(container0);
    assertNotNull(container1);
    assertEquals("0", container0.getProcessorId());
    assertEquals("1", container1.getProcessorId());
    assertEquals(5, container0.getTasks().size());
    assertEquals(4, container1.getTasks().size());

    assertTrue(container0.getTasks().containsKey(getTaskName(0)));
    assertTrue(container0.getTasks().containsKey(getTaskName(2)));
    assertTrue(container0.getTasks().containsKey(getTaskName(4)));
    assertTrue(container0.getTasks().containsKey(getTaskName(6)));
    assertTrue(container0.getTasks().containsKey(getTaskName(8)));
    assertTrue(container1.getTasks().containsKey(getTaskName(1)));
    assertTrue(container1.getTasks().containsKey(getTaskName(3)));
    assertTrue(container1.getTasks().containsKey(getTaskName(5)));
    assertTrue(container1.getTasks().containsKey(getTaskName(7)));

    verify(taskAssignmentManager, never()).writeTaskContainerMapping(anyString(), anyString());
    verify(taskAssignmentManager, never()).deleteTaskContainerMappings(anyCollection());
  }

  /**
   * Verifies the ability to have a custom task-container mapping that is *deliberately* unbalanced.
   *
   * Before:
   *  C0  C1
   * --------
   *  T0  T6
   *  T1  T7
   *  T2  T8
   *  T3
   *  T4
   *  T5
   *
   *  After:
   *  C0  C1
   * --------
   *  T0  T6
   *  T1  T7
   *  T2  T8
   *  T3
   *  T4
   *  T5
   */
  @Test
  public void testBalancerAfterContainerSameCustomAssignment() {
    Set<TaskModel> taskModels = generateTaskModels(9);

    Map<String, String> prevTaskToContainerMapping = new HashMap<>();
    prevTaskToContainerMapping.put(getTaskName(0).getTaskName(), "0");
    prevTaskToContainerMapping.put(getTaskName(1).getTaskName(), "0");
    prevTaskToContainerMapping.put(getTaskName(2).getTaskName(), "0");
    prevTaskToContainerMapping.put(getTaskName(3).getTaskName(), "0");
    prevTaskToContainerMapping.put(getTaskName(4).getTaskName(), "0");
    prevTaskToContainerMapping.put(getTaskName(5).getTaskName(), "0");
    prevTaskToContainerMapping.put(getTaskName(6).getTaskName(), "1");
    prevTaskToContainerMapping.put(getTaskName(7).getTaskName(), "1");
    prevTaskToContainerMapping.put(getTaskName(8).getTaskName(), "1");
    when(taskAssignmentManager.readTaskAssignment()).thenReturn(prevTaskToContainerMapping);

    Set<ContainerModel> containers = new GroupByContainerCount(2).balance(taskModels, localityManager);

    Map<String, ContainerModel> containersMap = new HashMap<>();
    for (ContainerModel container : containers) {
      containersMap.put(container.getProcessorId(), container);
    }

    assertEquals(2, containers.size());
    ContainerModel container0 = containersMap.get("0");
    ContainerModel container1 = containersMap.get("1");
    assertNotNull(container0);
    assertNotNull(container1);
    assertEquals("0", container0.getProcessorId());
    assertEquals("1", container1.getProcessorId());
    assertEquals(6, container0.getTasks().size());
    assertEquals(3, container1.getTasks().size());

    assertTrue(container0.getTasks().containsKey(getTaskName(0)));
    assertTrue(container0.getTasks().containsKey(getTaskName(1)));
    assertTrue(container0.getTasks().containsKey(getTaskName(2)));
    assertTrue(container0.getTasks().containsKey(getTaskName(3)));
    assertTrue(container0.getTasks().containsKey(getTaskName(4)));
    assertTrue(container0.getTasks().containsKey(getTaskName(5)));
    assertTrue(container1.getTasks().containsKey(getTaskName(6)));
    assertTrue(container1.getTasks().containsKey(getTaskName(7)));
    assertTrue(container1.getTasks().containsKey(getTaskName(8)));

    verify(taskAssignmentManager, never()).writeTaskContainerMapping(anyString(), anyString());
    verify(taskAssignmentManager, never()).deleteTaskContainerMappings(anyCollection());
  }

  /**
   * Verifies the ability to have a custom task-container mapping that is *deliberately* unbalanced.
   *
   * Before:
   *  C0  C1
   * --------
   *  T0  T1
   *      T2
   *      T3
   *      T4
   *      T5
   *
   *  After:
   *  C0  C1  C2
   * ------------
   *  T0  T1  T4
   *  T5  T2  T3
   *
   *  The key here is that C0, which is not one of the new containers was under-allocated.
   *  This is an important case because this scenario, while impossible with GroupByContainerCount.group()
   *  could occur when the grouper class is switched or if there is a custom mapping.
   */
  @Test
  public void testBalancerAfterContainerSameCustomAssignmentAndContainerIncrease() {
    Set<TaskModel> taskModels = generateTaskModels(6);

    Map<String, String> prevTaskToContainerMapping = new HashMap<>();
    prevTaskToContainerMapping.put(getTaskName(0).getTaskName(), "0");
    prevTaskToContainerMapping.put(getTaskName(1).getTaskName(), "1");
    prevTaskToContainerMapping.put(getTaskName(2).getTaskName(), "1");
    prevTaskToContainerMapping.put(getTaskName(3).getTaskName(), "1");
    prevTaskToContainerMapping.put(getTaskName(4).getTaskName(), "1");
    prevTaskToContainerMapping.put(getTaskName(5).getTaskName(), "1");
    when(taskAssignmentManager.readTaskAssignment()).thenReturn(prevTaskToContainerMapping);

    Set<ContainerModel> containers = new GroupByContainerCount(3).balance(taskModels, localityManager);

    Map<String, ContainerModel> containersMap = new HashMap<>();
    for (ContainerModel container : containers) {
      containersMap.put(container.getProcessorId(), container);
    }

    assertEquals(3, containers.size());
    ContainerModel container0 = containersMap.get("0");
    ContainerModel container1 = containersMap.get("1");
    ContainerModel container2 = containersMap.get("2");
    assertNotNull(container0);
    assertNotNull(container1);
    assertNotNull(container2);
    assertEquals("0", container0.getProcessorId());
    assertEquals("1", container1.getProcessorId());
    assertEquals("2", container2.getProcessorId());
    assertEquals(2, container0.getTasks().size());
    assertEquals(2, container1.getTasks().size());
    assertEquals(2, container1.getTasks().size());

    assertTrue(container0.getTasks().containsKey(getTaskName(0)));
    assertTrue(container0.getTasks().containsKey(getTaskName(5)));
    assertTrue(container1.getTasks().containsKey(getTaskName(1)));
    assertTrue(container1.getTasks().containsKey(getTaskName(2)));
    assertTrue(container2.getTasks().containsKey(getTaskName(4)));
    assertTrue(container2.getTasks().containsKey(getTaskName(3)));

    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(0).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(1).getTaskName(), "1");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(2).getTaskName(), "1");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(3).getTaskName(), "2");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(4).getTaskName(), "2");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(5).getTaskName(), "0");

    verify(taskAssignmentManager, never()).deleteTaskContainerMappings(anyCollection());
  }

  @Test
  public void testBalancerOldContainerCountOne() {
    Set<TaskModel> taskModels = generateTaskModels(3);
    Set<ContainerModel> prevContainers = new GroupByContainerCount(1).group(taskModels);
    Map<String, String> prevTaskToContainerMapping = generateTaskContainerMapping(prevContainers);
    when(taskAssignmentManager.readTaskAssignment()).thenReturn(prevTaskToContainerMapping);

    Set<ContainerModel> groupContainers = new GroupByContainerCount(3).group(taskModels);
    Set<ContainerModel> balanceContainers = new GroupByContainerCount(3).balance(taskModels, localityManager);

    // Results should be the same as calling group()
    assertEquals(groupContainers, balanceContainers);

    // Verify task mappings are saved
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(0).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(1).getTaskName(), "1");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(2).getTaskName(), "2");

    verify(taskAssignmentManager, never()).deleteTaskContainerMappings(anyCollection());
  }

  @Test
  public void testBalancerNewContainerCountOne() {
    Set<TaskModel> taskModels = generateTaskModels(3);
    Set<ContainerModel> prevContainers = new GroupByContainerCount(3).group(taskModels);
    Map<String, String> prevTaskToContainerMapping = generateTaskContainerMapping(prevContainers);
    when(taskAssignmentManager.readTaskAssignment()).thenReturn(prevTaskToContainerMapping);

    Set<ContainerModel> groupContainers = new GroupByContainerCount(1).group(taskModels);
    Set<ContainerModel> balanceContainers = new GroupByContainerCount(1).balance(taskModels, localityManager);

    // Results should be the same as calling group()
    assertEquals(groupContainers, balanceContainers);

    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(0).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(1).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(2).getTaskName(), "0");

    verify(taskAssignmentManager, never()).deleteTaskContainerMappings(anyCollection());
  }

  @Test
  public void testBalancerEmptyTaskMapping() {
    Set<TaskModel> taskModels = generateTaskModels(3);
    when(taskAssignmentManager.readTaskAssignment()).thenReturn(new HashMap<String, String>());

    Set<ContainerModel> groupContainers = new GroupByContainerCount(1).group(taskModels);
    Set<ContainerModel> balanceContainers = new GroupByContainerCount(1).balance(taskModels, localityManager);

    // Results should be the same as calling group()
    assertEquals(groupContainers, balanceContainers);

    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(0).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(1).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(2).getTaskName(), "0");

    verify(taskAssignmentManager, never()).deleteTaskContainerMappings(anyCollection());
  }

  @Test
  public void testGroupTaskCountIncrease() {
    int taskCount = 3;
    Set<TaskModel> taskModels = generateTaskModels(taskCount);
    Set<ContainerModel> prevContainers = new GroupByContainerCount(2).group(generateTaskModels(taskCount - 1)); // Here's the key step
    Map<String, String> prevTaskToContainerMapping = generateTaskContainerMapping(prevContainers);
    when(taskAssignmentManager.readTaskAssignment()).thenReturn(prevTaskToContainerMapping);

    Set<ContainerModel> groupContainers = new GroupByContainerCount(1).group(taskModels);
    Set<ContainerModel> balanceContainers = new GroupByContainerCount(1).balance(taskModels, localityManager);

    // Results should be the same as calling group()
    assertEquals(groupContainers, balanceContainers);

    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(0).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(1).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(2).getTaskName(), "0");

    verify(taskAssignmentManager).deleteTaskContainerMappings(anyCollection());
  }

  @Test
  public void testGroupTaskCountDecrease() {
    int taskCount = 3;
    Set<TaskModel> taskModels = generateTaskModels(taskCount);
    Set<ContainerModel> prevContainers = new GroupByContainerCount(3).group(generateTaskModels(taskCount + 1)); // Here's the key step
    Map<String, String> prevTaskToContainerMapping = generateTaskContainerMapping(prevContainers);
    when(taskAssignmentManager.readTaskAssignment()).thenReturn(prevTaskToContainerMapping);

    Set<ContainerModel> groupContainers = new GroupByContainerCount(1).group(taskModels);
    Set<ContainerModel> balanceContainers = new GroupByContainerCount(1).balance(taskModels, localityManager);

    // Results should be the same as calling group()
    assertEquals(groupContainers, balanceContainers);

    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(0).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(1).getTaskName(), "0");
    verify(taskAssignmentManager).writeTaskContainerMapping(getTaskName(2).getTaskName(), "0");

    verify(taskAssignmentManager).deleteTaskContainerMappings(anyCollection());
  }

  @Test(expected = IllegalArgumentException.class)
  public void testBalancerNewContainerCountGreaterThanTasks() {
    Set<TaskModel> taskModels = generateTaskModels(3);
    Set<ContainerModel> prevContainers = new GroupByContainerCount(3).group(taskModels);
    Map<String, String> prevTaskToContainerMapping = generateTaskContainerMapping(prevContainers);
    when(taskAssignmentManager.readTaskAssignment()).thenReturn(prevTaskToContainerMapping);

    new GroupByContainerCount(5).balance(taskModels, localityManager);     // Should throw
  }

  @Test(expected = IllegalArgumentException.class)
  public void testBalancerEmptyTasks() {
    Set<TaskModel> taskModels = generateTaskModels(3);
    Set<ContainerModel> prevContainers = new GroupByContainerCount(3).group(taskModels);
    Map<String, String> prevTaskToContainerMapping = generateTaskContainerMapping(prevContainers);
    when(taskAssignmentManager.readTaskAssignment()).thenReturn(prevTaskToContainerMapping);

    new GroupByContainerCount(5).balance(new HashSet<TaskModel>(), localityManager);     // Should throw
  }

  @Test(expected = UnsupportedOperationException.class)
  public void testBalancerResultImmutable() {
    Set<TaskModel> taskModels = generateTaskModels(3);
    Set<ContainerModel> prevContainers = new GroupByContainerCount(3).group(taskModels);
    Map<String, String> prevTaskToContainerMapping = generateTaskContainerMapping(prevContainers);
    when(taskAssignmentManager.readTaskAssignment()).thenReturn(prevTaskToContainerMapping);

    Set<ContainerModel> containers = new GroupByContainerCount(2).balance(taskModels, localityManager);
    containers.remove(containers.iterator().next());
  }

  @Test(expected = SamzaException.class)
  public void testBalancerThrowsOnNonIntegerContainerIds() {
    Set<TaskModel> taskModels = generateTaskModels(3);
    Set<ContainerModel> prevContainers = new HashSet<>();
    taskModels.forEach(model -> {
        prevContainers.add(
          new ContainerModel(UUID.randomUUID().toString(), -1, Collections.singletonMap(model.getTaskName(), model)));
      });
    Map<String, String> prevTaskToContainerMapping = generateTaskContainerMapping(prevContainers);
    when(taskAssignmentManager.readTaskAssignment()).thenReturn(prevTaskToContainerMapping);

    new GroupByContainerCount(3).balance(taskModels, localityManager); //Should throw

  }

  @Test
  public void testBalancerWithNullLocalityManager() {
    Set<TaskModel> taskModels = generateTaskModels(3);

    Set<ContainerModel> groupContainers = new GroupByContainerCount(3).group(taskModels);
    Set<ContainerModel> balanceContainers = new GroupByContainerCount(3).balance(taskModels, null);

    // Results should be the same as calling group()
    assertEquals(groupContainers, balanceContainers);
  }
}


text:
package io.renren.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import io.renren.dao.YbmDao;
import io.renren.entity.YbmEntity;
import io.renren.service.YbmService;

@Service("ybmService")
public class YbmServiceImpl implements YbmService {
	@Autowired
	private YbmDao ybmDao;

	@Override
	public YbmEntity queryObject(Integer id){
		return ybmDao.queryObject(id);
	}

	@Override
	public List<YbmEntity> queryList(Map<String, Object> map){
		return ybmDao.queryList(map);
	}

	@Override
	public int queryTotal(Map<String, Object> map){
		return ybmDao.queryTotal(map);
	}

	@Override
	public void save(YbmEntity ybm){
		ybmDao.save(ybm);
	}

	@Override
	public void update(YbmEntity ybm){
		ybmDao.update(ybm);
	}

	@Override
	public void delete(Integer id){
		ybmDao.delete(id);
	}

	@Override
	public void deleteBatch(Integer[] ids){
		ybmDao.deleteBatch(ids);
	}

}

redpajama_set_name: RedPajamaGithub


text:
/*! \file ored/marketdata/inflationcapfloorpricesurface.hpp
    \brief inflation cap floor price surface class
    \ingroup curves
*/

#pragma once

#include <ql/experimental/inflation/cpicapfloortermpricesurface.hpp>
#include <ql/termstructures/inflationtermstructure.hpp>

#include <ored/configuration/conventions.hpp>
#include <ored/configuration/curveconfigurations.hpp>
#include <ored/configuration/inflationcapfloorpricesurfaceconfig.hpp>
#include <ored/marketdata/curvespec.hpp>
#include <ored/marketdata/inflationcurve.hpp>
#include <ored/marketdata/loader.hpp>
#include <ored/marketdata/yieldcurve.hpp>

using QuantLib::Date;
using QuantLib::InflationTermStructure;
using QuantLib::CPICapFloorTermPriceSurface;
using ore::data::CurveConfigurations;
using ore::data::Conventions;

namespace ore {
namespace data {

//! Wrapper class for building inflation curves
/*!
  \ingroup curves
*/
class InflationCapFloorPriceSurface {
public:
    InflationCapFloorPriceSurface() {}
    InflationCapFloorPriceSurface(Date asof, InflationCapFloorPriceSurfaceSpec spec, const Loader& loader,
                                  const CurveConfigurations& curveConfigs,
                                  map<string, boost::shared_ptr<YieldCurve>>& yieldCurves,
                                  map<string, boost::shared_ptr<InflationCurve>>& inflationCurves);

    //! getters
    const InflationCapFloorPriceSurfaceSpec& spec() const { return spec_; }

    const boost::shared_ptr<CPICapFloorTermPriceSurface> inflationCapFloorPriceSurface() const { return surface_; }

private:
    InflationCapFloorPriceSurfaceSpec spec_;
    boost::shared_ptr<CPICapFloorTermPriceSurface> surface_;
};
}
}


text:
{% extends "satchless/base.html" %}
{% load i18n %}
{% load pagination_tags %}
{% load prices %}
{% load product_prices %}
{% load satchless_image %}

{% block title %}{{ block.super }} — {{ product.name }}{% endblock %}

{% block body-class %}{{ block.super }} {% if path %}cat-{{ path.0.slug }} {% endif %}product{% endblock %}

{% block extra-body %}
{{ block.super }}
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/cloud-zoom.css" />

{% endblock %}

{% block breadcrumbs %}
{% if path %}

{% spaceless %}
    {% for category in path %}

{{ category }}

    {% endfor %}
{% endspaceless %}

{% endif %}
{% endblock %}

{% block content %}

    {% if product.main_image %}

    {% endif %}

        <form action="" method="post">

                {% if product.make %}
                    {{ product.make }}
                {% endif %}

{{ product.name }}

                        {{ product.description|linebreaks }}

                {% csrf_token %}

                    {{ product.cart_form.as_table }}

            {% product_price_range product as price_range %}
            {% product_price_range product discount=0 as undiscounted_price_range %}
            {% if price_range.min_price != price_range.max_price %}
                {% if price_range.min_price != undiscounted_price_range.min_price or price_range.max_price != undiscounted_price_range.max_price %}
                        {{ undiscounted_price_range.min_price|gross|floatformat:2 }} – {{ undiscounted_price_range.max_price|gross|floatformat:2 }}
                {% endif %}
                        {{ price_range.min_price|gross|floatformat:2 }}{{ price_range.min_price|currency }} – {{ price_range.max_price|gross|floatformat:2 }}{{ price_range.max_price|currency }}
            {% else %}
                {% if price_range.max_price != undiscounted_price_range.max_price %}
                        {{ undiscounted_price_range.max_price|gross|floatformat:2 }}
                {% endif %}
                        {{ price_range.min_price|gross|floatformat:2 }}{{ price_range.min_price|currency }}
            {% endif %}

                            Inclusive VAT

                            Exclusive shipping costs

                    <input class="button cart" name="cart" type="submit" value="{% trans "Add to cart" %}" />
                    <input class="wishlist" name="wishlist" type="submit" value="{% trans "Add to whishlist" %}" />

        </form>

{% spaceless %}
{% for image in product.images.all %}
    {% with image|at_size:'product-thumb' as thumb %}
        {% with image|at_size:'product-detail' as detail %}

        {% endwith %}
    {% endwith %}
{% endfor %}
{% endspaceless %}

{% endblock %}


text:
package magelets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class optMAGE_1
 */
public class optMAGE_1 extends Magelet {

	private static final long serialVersionUID = 1L;

	private static final String validHeaders = "validate.txt";
    private static final String script = "optMAGEv0.9.pl";
    private static final String oligoFile = "OUToligos.txt";
    private static final String dumpFile = "OUTalldump.txt";
    private static final String inputParameterFileName = "INPUTparam.txt";
    private static final String servletFolder ="/optMage_1/";
    private static final String inputTargetFileName = "INPUTtarg.txt";
    private static final String inputGenomeFileName = "genome.fasta";

    /**
     * @see Magelet#Magelet()
     */
    public optMAGE_1() {
        super();
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		// ENSURE THAT THE SERVER.XML FILE HAS HTTP CONNECTOR SET TO maxPostSize="25097152" or megabytes
			//no longer necessary, but still a good idea- MageEditor will now deliver the genome file in smaller slices

		// Set response type and create an output printer
		response.setContentType("application/x-www-form-urlencoded");
		PrintWriter out = response.getWriter();

		// Get Servlet Directory
		String source = getDirectory(servletFolder) + "/master/";

		System.out.println("POST Received");

		// Load and validate parameters
		Map<String,String[]> parameters = load(request);
		try{
			if (validate(source+validHeaders,parameters)) {

				// Extract the user ID
				String user_id = parameters.get("id")[0];
				String directory = getDirectory(servletFolder)+"/copy"+user_id+"/" ;

				// Try to make a new folder
				TextFile.copyDirectory(source, directory );
				System.out.println("Valid Headers");
				TextFile.deleteIfPossible(directory+oligoFile);
				TextFile.deleteIfPossible(directory+dumpFile);
			    TextFile.deleteIfPossible(directory+inputTargetFileName);
			    TextFile.deleteIfPossible(directory+inputParameterFileName);

				generate(directory, inputGenomeFileName, MageEditor.GENOME, parameters);
				//System.out.println("Folders Made");
				// Something related to the genome would go here

				// Execute the optMAGE script
				if (Boolean.valueOf(parameters.get(MageEditor.RUN)[0])){
					// Generate the inputParameterFile and inputTargetFile and write those to file system
					generate(directory, inputParameterFileName, MageEditor.PARAMETER, parameters );
					generate(directory, inputTargetFileName, MageEditor.TARGET, parameters );

					execute(directory, script);
				}
				// Read the MAGE results;
			    this.map.put( MageEditor.RESULT, TextFile.getLinesAsArray(directory+oligoFile ));
			    this.result = this.buildURLfromMap();

			    // Delete the files we just created
			    //TextFile.delete(directory+oligoFile);
			    TextFile.deleteIfPossible(directory+dumpFile);
			    // Something about renaming the genome file would go here.
			    //TextFile.delete(directory+inputTargetFileName);
			    //TextFile.delete(directory+inputParameterFileName);
			}
			//else { this.result = "Invalid Request Parameters"; }
		}
		catch (Exception EE){
			StringBuilder err = new StringBuilder(EE.toString());
			//get the error stream from a failed OptMage script run
			try{
				String user_id = parameters.get("id")[0];
				String directory = getDirectory(servletFolder)+"/copy"+user_id+"/" ;
				for (String line : TextFile.getLinesAsArray(directory+"OptMageERR.txt")){
					err.append("\n" + line);
				}
			}
			catch(IOException e){};

			EE.printStackTrace();
			this.map.remove(MageEditor.ERROR);
			this.map.put(MageEditor.ERROR, new String[] {err.toString()});
			this.result = this.buildURLfromMap();
		}
		finally{

			// Print to console and return the results
			out.write(this.result);
			//System.out.println(this.result);

			// Close the output Stream.
			out.close();
		}

	}
}


text:
<?php
/*                                                                        *
 * This script belongs to the TYPO3 package "Extension Builder".                  *
 *                                                                        *
 * It is free software; you can redistribute it and/or modify it under    *
 * the terms of the GNU Lesser General Public License as published by the *
 * Free Software Foundation, either version 3 of the License, or (at your *
 * option) any later version.                                             *
 *                                                                        *
 * This script is distributed in the hope that it will be useful, but     *
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
 * General Public License for more details.                               *
 *                                                                        *
 * You should have received a copy of the GNU Lesser General Public       *
 * License along with the script.                                         *
 * If not, see http://www.gnu.org/licenses/lgpl.html                      *
 *                                                                        *
 * The TYPO3 project - inspiring people to share!                         *
 *                                                                        */

/**
 * Wrapper for PHPs ucfirst function.
 * @see http://www.php.net/manual/en/ucfirst
 *
 * = Examples =
 *
 * <code title="Example">
 * <k:uppercaseFirst>{textWithMixedCase}</k:uppercaseFirst>
 * </code>
 *
 * Output:
 * TextWithMixedCase
 *
 * @version $Id: $
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
 * @scope prototype
 */
class Tx_ExtensionBuilder_ViewHelpers_Format_LowercaseFirstViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {

	/**
	 * Lowercase first character
	 *
	 * @return string The altered string.
	 */
	public function render() {
		$content = $this->renderChildren();
		return \TYPO3\CMS\Core\Utility\GeneralUtility::lcfirst($content);
	}
}

?>


text:
===========
Development
===========

Setting up development environment
---------------------------------------------------
This section shows a way to configure a development environment that allows you to run tests and build documentation.

The recommended way to run the unit tests is to use the Dockerized Linux workspace via the Makefile provided at :code:`docker/Makefile`.
The commands below will build the Docker image, start a running container with your local hops-util-py source code mounted
into it from the host at :code:`/hops`. A python 3.6 environment is available in the container at :code:`/hops_venv3.6/`.
Moreover, the commands below will also open a BASH shell into it (you must have GNU Make and Docker installed beforehand (:code:`sudo apt-get install docker.io`)):

.. code-block:: bash

    cd docker # go to where Makefile is located

    # Build docker container and mount (you might need sudo),
    # this will fail if you already have a container named "hops" running
    # (if that is the case, just run `make shell` (or `sudo make shell`) to login to the existing container instead,
    # or if you want the kill the existing container and re-build, you can execute: `make clean` and then make build run shell)
    make build run shell # this might require sudo

    # Run the unit tests
    cd /hops/docker # once inside docker
    ./run_tests.sh 3.6 # for python 3.6
    ./run_tests.sh 3.6 -s # run tests with verbose flag

    # Alternatively you can skip the bash scripts and write the commands yourself (this gives you more control):
    cd /hops #inside the container
    source /hops_venv3.6/bin/activate # for python 3.6
    pip install -e . # install latest source
    pytest -v hops # run tests, note if you want to re-run just edit the code in your host and run the same command, you do not have to re-run pip install..

The docker approach is recommended if you already have an existing SPARK/Hadoop installation in your environment to avoid conflicts
( for example if you want to run the tests from inside a VM where Hops is deployed). Moreover, using docker makes it simpler to test python 3.6.

Also note that when you edit files inside your local machine the changes will automatically get reflected in the docker
container since the directory is mounted there so you can easily re-run tests during development as you do code-changes.

To open up a shell in an already built :code:`hops` container:

.. code-block:: bash

    cd docker # go to where Makefile is located
    make shell

To kill an existing :code:`hops` container:

.. code-block:: bash

    cd docker # go to where Makefile is located
    make clean

If you want to run the tests in your local environment (watch out for spark/hadoop/environment conflicts) you can use the following setup:

.. code-block:: bash

    sudo apt-get install python3-dev  # install python3
    sudo apt-get install libsasl2-dev # for SSL used in kafka
    pip install virtualenv
    rm -rf env # remove old env if it exists
    virtualenv env --python <path-to-python3 or python2> #creates a virtual env for tests (e.g virtualenv env --python /usr/bin/python3.5)
    source env/bin/activate #activates the env
    pip install -U pip setuptools #install dependency
    pip install -e .[docs,tf,test] #install hops together with dependencies and extra dependencies for docs,tensorflow and tests
    pytest -v hops # run tests

Unit tests
----------
To run unit tests locally:

.. code-block:: bash

    pytest -v hops # Runs all tests
    pytest -v hops/tests/test_featurestore.py # Run specific test module
    pytest -v hops/tests/test_featurestore.py -k 'test_project_featurestore' # Run specific test in module
    pytest -m prepare # run test setups before parallel execution. **Note**: Feature store test suite is best run sequentially, otherwise race-conditions might cause errors.
    pytest -v hops -n 5 # Run tests in parallel with 5 workers. (Run prepare first)
    pytest -v hops -n auto #Run with automatically selected number of workers
    pytest -v hops -s # run with printouts (stdout)

Documentation
-------------

We use sphinx to automatically generate API-docs

.. code-block:: bash

    pip install -e .[docs]
    cd docs; make html

Integration Tests
-------------

The notebooks in :code:`it_tests/` are used for integration testing by running them as jobs on a Hopsworks installation.
The integration tests can be triggered from https://github.com/logicalclocks/hops-testing by using the following steps:

1. Open a PR in hops-testing and override the :code:`test_manifesto` with the cookbooks you want to test
2. In your PR, add the following attribute in your vagrantfiles to run the integration tests: :code:`test:hopsworks:it = true`,
   e.g in Vagrantfile-centos and Vagrantfile-ubuntu add:

.. code-block:: bash

    config.vm.provision :chef_solo do |chef|
        chef.cookbooks_path = "cookbooks"
        chef.json = {
          "test" => {
            "hopsworks" => {
	           "it" => true
            }
          }
        }

3. If you need to test a version of hops-util-py that is not merged you can set the chef attributes in your cluster-definition
   as follows to use a branch called :code:`test` in repository of :code:`kim/hops-util-py`:

.. code-block:: bash

    conda:
      hops-util-py:
        install-mode: "git"
        branch: "test"
        repo: "kim"


text:
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { Creator, LikeRelation } from '../../../model/app.model';
import { IdentityService } from '../../../services/app.service';

@Component({
    selector: 'tassel-common-likeuser',
    templateUrl: 'like-user.html',
    styleUrls: [
        'like-user.scss'
    ]
})
export class LikeUserDivComponent {

    @Input()
    private user: LikeRelation;
    public get Creator() { return this.user.Creator; }

    @Output()
    OnUserClicked = new EventEmitter<string>();

    public readonly GoToUserDetails = (mentioned?: Creator) => {
        this.OnUserClicked.emit(this.Creator.UUID);
    }

}


text:
"""
Test functions for models.GLM
"""

import numpy as np

from .. import family
from ..glm import Model as GLM

from nose.tools import assert_equal, assert_true, assert_false

VARS = {}

def setup():
    rng = np.random.RandomState(20110928)
    VARS['X'] = rng.standard_normal((40,10))
    Y = rng.standard_normal((40,))
    VARS['Y'] = np.greater(Y, 0)

def test_Logistic():
    X = VARS['X']
    Y = VARS['Y']
    cmodel = GLM(design=X, family=family.Binomial())
    results = cmodel.fit(Y)
    assert_equal(results.df_resid, 30)

def test_cont():
    # Test continue function works as expected
    X = VARS['X']
    Y = VARS['Y']
    cmodel = GLM(design=X, family=family.Binomial())
    cmodel.fit(Y)
    assert_true(cmodel.cont(0))
    assert_false(cmodel.cont(np.inf))

def test_Logisticdegenerate():
    X = VARS['X'].copy()
    X[:,0] = X[:,1] + X[:,2]
    Y = VARS['Y']
    cmodel = GLM(design=X, family=family.Binomial())
    results = cmodel.fit(Y)
    assert_equal(results.df_resid, 31)


text:
#ifndef _HEXIFY_H_
#define _HEXIFY_H_

#include <stddef.h>
#include <stdint.h>

/**
 * hexify(in, out, len):
 * Convert ${len} bytes from ${in} into hexadecimal, writing the resulting
 * 2 * ${len} bytes to ${out}; and append a NUL byte.
 */
void hexify(const uint8_t *, char *, size_t);

/**
 * unhexify(in, out, len):
 * Convert 2 * ${len} hexadecimal characters from ${in} to ${len} bytes
 * and write them to ${out}.  This function will only fail if the input is
 * not a sequence of hexadecimal characters.
 */
int unhexify(const char *, uint8_t *, size_t);

#endif /* !_HEXIFY_H_ */


text:
package ua.org.dector.space_lander.screens.menu;

import com.badlogic.gdx.scenes.scene2d.ActorEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
import ua.org.dector.gcore.game.TableScreen;
import ua.org.dector.gcore.managers.SoundManager;
import ua.org.dector.space_lander.Lander;
import ua.org.dector.space_lander.constants.Labels;
import ua.org.dector.space_lander.constants.LanderMusic;
import ua.org.dector.space_lander.constants.LanderSounds;

import static com.badlogic.gdx.Input.Keys;
import static ua.org.dector.space_lander.constants.UISizes.*;

/**
 * @author dector (dector9@gmail.com)
 */
public class MainMenuScreen extends TableScreen<Lander> {
    public MainMenuScreen(Lander lander) {
        super(lander);
    }

    public void show() {
        final SoundManager soundManager = game.getSoundManager();

        game.getMusicManager().play(LanderMusic.MENU, true);

        Skin skin = game.getGraphics().getSkin();
        Table table = getTable();

        Button btnPlay = new TextButton(Labels.PLAY, skin);
        btnPlay.addListener(new ClickListener() {
            public void clicked(ActorEvent event, float x, float y) {
                soundManager.play(LanderSounds.MENU_CLICK);

                game.setScreen(new PlayScreen(game));
            }
        });

        Button btnOptions = new TextButton(Labels.OPTIONS, skin);
        btnOptions.addListener(new ClickListener() {
            public void clicked(ActorEvent event, float x, float y) {
                soundManager.play(LanderSounds.MENU_CLICK);

                game.setScreen(new OptionsScreen(game));
            }
        });

        Button btnExit = new TextButton(Labels.EXIT, skin);
        btnExit.addListener(new ClickListener() {
            public void clicked(ActorEvent event, float x, float y) {
                soundManager.play(LanderSounds.MENU_CLICK);

                game.exit();
            }
        });

        table.add(Labels.TITLE).spaceBottom(TITLE_BOTTOM_SPACE);
        table.row();
        table.add(btnPlay).size(BUTTONS_WIDTH, BUTTONS_HEIGHT).
                spaceBottom(BOTTOM_SPACE).fill().uniform();
        table.row();
        table.add(btnOptions).size(BUTTONS_WIDTH, BUTTONS_HEIGHT).
                spaceBottom(BOTTOM_SPACE).fill().uniform();
        table.row();
        table.add(btnExit).size(BUTTONS_WIDTH, BUTTONS_HEIGHT).fill().uniform();
    }

    public boolean keyDown(int keycode) {
        switch (keycode) {
            case Keys.ESCAPE: game.exit(); break;
        }

        return true;
    }
}


text:
function [subject, set] = parseSS(fileName)
% This function parses out the subject and set values from data file names

f = lower(fileName);
[subject, remain] = strtok(f,'_');
[set,] = strtok(remain,'_');


text:
#include "test.h"

#include "testutil.h"
#include "warnless.h"
#include "memdebug.h"

int test(char *URL)
{
  CURL *curls = NULL;
  int res = 0;
  curl_mimepart *field = NULL;
  curl_mime *mime = NULL;

  global_init(CURL_GLOBAL_ALL);
  easy_init(curls);

  mime = curl_mime_init(curls);
  field = curl_mime_addpart(mime);
  curl_mime_name(field, "name");
  curl_mime_data(field, "short value", CURL_ZERO_TERMINATED);

  easy_setopt(curls, CURLOPT_URL, URL);
  easy_setopt(curls, CURLOPT_HEADER, 1L);
  easy_setopt(curls, CURLOPT_VERBOSE, 1L);
  easy_setopt(curls, CURLOPT_MIMEPOST, mime);
  easy_setopt(curls, CURLOPT_NOPROGRESS, 1L);

  res = curl_easy_perform(curls);
  if(res)
    goto test_cleanup;

  /* Alter form and resubmit. */
  curl_mime_data(field, "long value for length change", CURL_ZERO_TERMINATED);
  res = curl_easy_perform(curls);

test_cleanup:
  curl_mime_free(mime);
  curl_easy_cleanup(curls);
  curl_global_cleanup();
  return (int) res; /* return the final return code */
}


text:
@implementation TFFReachabilityDelegate

- (void)networkStatusChanged:(TFFReachabilityStatus)status {
    [self.delegate networkStatusChanged:status];
}

@end


text:
from flask import Flask
from edmunds.foundation.concerns.config import Config as ConcernsConfig
from edmunds.foundation.concerns.runtimeenvironment import RuntimeEnvironment as ConcernsRuntimeEnvironment
from edmunds.foundation.concerns.serviceproviders import ServiceProviders as ConcernsServiceProviders
from edmunds.foundation.concerns.middleware import Middleware as ConcernsMiddleware
from edmunds.foundation.concerns.storage import Storage as ConcernsStorage
from edmunds.foundation.concerns.session import Session as ConcernsSession
from edmunds.foundation.concerns.database import Database as ConcernsDatabase
from edmunds.foundation.concerns.localization import Localization as ConcernsLocalization
from edmunds.foundation.concerns.cache import Cache as ConcernsCache
from edmunds.foundation.concerns.auth import Auth as ConcernsAuth
from edmunds.exceptions.exceptionsserviceprovider import ExceptionsServiceProvider
from edmunds.log.providers.logserviceprovider import LogServiceProvider
from edmunds.session.providers.sessionserviceprovider import SessionServiceProvider
from edmunds.storage.providers.storageserviceprovider import StorageServiceProvider
from edmunds.database.providers.databaseserviceprovider import DatabaseServiceProvider
from edmunds.localization.providers.localizationserviceprovider import LocalizationServiceProvider
from edmunds.cache.providers.cacheserviceprovider import CacheServiceProvider
from edmunds.http.providers.httpserviceprovider import HttpServiceProvider
from edmunds.auth.providers.authserviceprovider import AuthServiceProvider
from edmunds.foundation.providers.runtimeenvironmentprovider import RuntimeEnvironmentServiceProvider
from edmunds.profiler.providers.profilerserviceprovider import ProfilerServiceProvider
from edmunds.config.config import Config
from edmunds.http.request import Request
from edmunds.http.response import Response
from edmunds.http.route import Route

class Application(Flask,
                  ConcernsConfig,
                  ConcernsRuntimeEnvironment,
                  ConcernsServiceProviders,
                  ConcernsMiddleware,
                  ConcernsStorage,
                  ConcernsSession,
                  ConcernsDatabase,
                  ConcernsLocalization,
                  ConcernsCache,
                  ConcernsAuth):
    """
    The Edmunds Application
    """

    request_class = Request
    response_class = Response
    config_class = Config

    def __init__(self, import_name, config_dirs=None, *args, **kwargs):
        """
        Initialize the application
        :param import_name:     Import name
        :type  import_name:     str
        :param config_dirs:     Configuration directories
        :type  config_dirs:     list
        :param args:            Additional args
        :type  args:            list
        :param kwargs:          Additional kwargs
        :type  kwargs:          dict
        """

        super(Application, self).__init__(import_name, *args, **kwargs)

        self.logger_name = 'edmunds.%s' % import_name

        self._init_config(config_dirs)
        self._init_database()

        self.register(RuntimeEnvironmentServiceProvider)
        self.register(ProfilerServiceProvider)
        self.register(HttpServiceProvider)
        self.register(StorageServiceProvider)
        self.register(ExceptionsServiceProvider)
        self.register(LogServiceProvider)
        self.register(SessionServiceProvider)
        self.register(DatabaseServiceProvider)
        self.register(CacheServiceProvider)
        self.register(LocalizationServiceProvider)
        self.register(AuthServiceProvider)

    def route(self, rule, **options):
        """
        Register a route
        This van be done the old skool way, or with the uses
        :param rule:    The rule for routing the request
        :type  rule:    str
        :param options: List of options
        :type  options: list
        :return:        Route instance or decorator function
        :rtype:         edmunds.http.route.Route
        """

        route = Route(self)

        # Register middleware that was given with the options
        if 'middleware' in options:
            for middleware in options.pop('middleware'):
                if isinstance(middleware, tuple):
                    route.middleware(middleware[0], *middleware[1:])
                else:
                    route.middleware(middleware)

        if 'uses' in options:
            # Add controller and method
            controller_class, method_name = options.pop('uses')
            route.uses(controller_class, method_name)

            return_value = route
        else:
            return_value = route.decorate

        # Define endpoint
        if 'endpoint' in options:
            endpoint = options.pop('endpoint')
        else:
            endpoint = 'edmunds.route.%s' % rule

        # Add route
        self.add_url_rule(rule, endpoint=endpoint, view_func=route.handle)

        return return_value


text:
package org.apache.maven.plugin.checkstyle;

import com.puppycrawl.tools.checkstyle.DefaultLogger;
import com.puppycrawl.tools.checkstyle.XMLLogger;
import com.puppycrawl.tools.checkstyle.api.AuditListener;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
import org.apache.maven.doxia.siterenderer.Renderer;
import org.apache.maven.doxia.tools.SiteTool;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.checkstyle.rss.CheckstyleRssGenerator;
import org.apache.maven.plugin.checkstyle.rss.CheckstyleRssGeneratorRequest;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.plexus.resource.ResourceManager;
import org.codehaus.plexus.resource.loader.FileResourceLoader;
import org.codehaus.plexus.util.PathTool;
import org.codehaus.plexus.util.StringUtils;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;

/**
 * Base abstract class for Checkstyle reports.
 *
 * @version $Id$
 * @since 2.8
 */
public abstract class AbstractCheckstyleReport
    extends AbstractMavenReport
{
    public static final String PLUGIN_RESOURCES = "org/apache/maven/plugin/checkstyle";

    protected static final String JAVA_FILES = "**\\/*.java";

    /**
     * Specifies the cache file used to speed up Checkstyle on successive runs.
     */
    @Parameter( defaultValue = "${project.build.directory}/checkstyle-cachefile" )
    protected String cacheFile;

    /**
     *

     * Specifies the location of the XML configuration to use.
     *

     *

     *

     * Potential values are a filesystem path, a URL, or a classpath resource.
     * This parameter expects that the contents of the location conform to the
     * xml format (Checkstyle Checker
     * module) configuration of rulesets.
     *

     *

     *

     * This parameter is resolved as resource, URL, then file. If successfully
     * resolved, the contents of the configuration is copied into the
     * ${project.build.directory}/checkstyle-configuration.xml
     * file before being passed to Checkstyle as a configuration.
     *

     *

     *

     * There are 4 predefined rulesets.
     *

     *

     *

     *
config/sun_checks.xml: Sun Checks.

     *
config/turbine_checks.xml: Turbine Checks.

     *
config/avalon_checks.xml: Avalon Checks.

     *
config/maven_checks.xml: Maven Source Checks.

     *

     */
    @Parameter( property = "checkstyle.config.location", defaultValue = "config/sun_checks.xml" )
    protected String configLocation;

    /**
     * Output errors to console.
     */
    @Parameter( property = "checkstyle.consoleOutput", defaultValue = "false" )
    protected boolean consoleOutput;

    /**
     * The file encoding to use when reading the source files. If the property project.build.sourceEncoding
     * is not set, the platform default encoding is used. Note: This parameter always overrides the
     * property charset from Checkstyle's TreeWalker module.
     *
     * @since 2.2
     */
    @Parameter( property = "encoding", defaultValue = "${project.build.sourceEncoding}" )
    protected String encoding;

    /**
     * Specifies if the build should fail upon a violation.
     */
    @Parameter( defaultValue = "false" )
    protected boolean failsOnError;

    /**
     *

     * Specifies the location of the License file (a.k.a. the header file) that
     * can be used by Checkstyle to verify that source code has the correct
     * license header.
     *

     *

     * You need to use ${checkstyle.header.file} in your Checkstyle xml
     * configuration to reference the name of this header file.
     *

     *

     * For instance:
     *

     *

     *
     * <module name="RegexpHeader">
     * <property name="headerFile" value="${checkstyle.header.file}"/>
     * </module>
     *
     *

     *
     * @since 2.0-beta-2
     */
    @Parameter( property = "checkstyle.header.file", defaultValue = "LICENSE.txt" )
    protected String headerLocation;

    /**
     * Skip entire check.
     *
     * @since 2.2
     */
    @Parameter( property = "checkstyle.skip", defaultValue = "false" )
    protected boolean skip;

    /**
     * The output directory for the report. Note that this parameter is only
     * evaluated if the goal is run directly from the command line. If the goal
     * is run indirectly as part of a site generation, the output directory
     * configured in Maven Site Plugin is used instead.
     */
    @Parameter( defaultValue = "${project.reporting.outputDirectory}", required = true )
    private File outputDirectory;

    /**
     * Specifies the path and filename to save the checkstyle output. The format
     * of the output file is determined by the outputFileFormat
     * parameter.
     */
    @Parameter( property = "checkstyle.output.file", defaultValue = "${project.build.directory}/checkstyle-result.xml" )
    private File outputFile;

    /**
     *

     * Specifies the location of the properties file.
     *

     *

     *

     * This parameter is resolved as URL, File then resource. If successfully
     * resolved, the contents of the properties location is copied into the
     * ${project.build.directory}/checkstyle-checker.properties
     * file before being passed to Checkstyle for loading.
     *

     *

     *

     * The contents of the propertiesLocation will be made
     * available to Checkstyle for specifying values for parameters within the
     * xml configuration (specified in the configLocation
     * parameter).
     *

     *
     * @since 2.0-beta-2
     */
    @Parameter( property = "checkstyle.properties.location" )
    protected String propertiesLocation;

    /**
     * Allows for specifying raw property expansion information.
     */
    @Parameter
    protected String propertyExpansion;

    /**
     * Specifies the location of the resources to be used for Checkstyle.
     *
     * @since 2.10
     */
    @Parameter( defaultValue = "${project.resources}", readonly = true )
    protected List<Resource> resources;

    /**
     * Specifies the location of the test resources to be used for Checkstyle.
     *
     * @since 2.11
     */
    @Parameter( defaultValue = "${project.testResources}", readonly = true )
    protected List<Resource> testResources;

    /**
     * Specifies the names filter of the source files to be used for Checkstyle.
     */
    @Parameter( property = "checkstyle.includes", defaultValue = JAVA_FILES, required = true )
    protected String includes;

    /**
     * Specifies the names filter of the source files to be excluded for
     * Checkstyle.
     */
    @Parameter( property = "checkstyle.excludes" )
    protected String excludes;

    /**
     * Specifies the names filter of the resource files to be used for Checkstyle.
     * @since 2.11
     */
    @Parameter( property = "checkstyle.resourceIncludes", defaultValue = "**/*.properties", required = true )
    protected String resourceIncludes;

    /**
     * Specifies the names filter of the resource files to be excluded for
     * Checkstyle.
     * @since 2.11
     */
    @Parameter( property = "checkstyle.resourceExcludes" )
    protected String resourceExcludes;

    /**
     * Specifies whether to include the resource directories in the check.
     * @since 2.11
     */
    @Parameter( property = "checkstyle.includeResources", defaultValue = "true", required = true )
    protected boolean includeResources;

    /**
     * Specifies whether to include the test resource directories in the check.
     * @since 2.11
     */
    @Parameter( property = "checkstyle.includeTestResources", defaultValue = "true", required = true )
    protected boolean includeTestResources;

    /**
     * Specifies the location of the source directory to be used for Checkstyle.
     */
    @Parameter( defaultValue = "${project.build.sourceDirectory}", required = true )
    protected File sourceDirectory;

    /**
     * Specifies the location of the test source directory to be used for
     * Checkstyle.
     *
     * @since 2.2
     */
    @Parameter( defaultValue = "${project.build.testSourceDirectory}" )
    protected File testSourceDirectory;

    /**
     * Include or not the test source directory to be used for Checkstyle.
     *
     * @since 2.2
     */
    @Parameter( defaultValue = "false" )
    protected boolean includeTestSourceDirectory;

    /**
     * The key to be used in the properties for the suppressions file.
     *
     * @since 2.1
     */
    @Parameter( property = "checkstyle.suppression.expression", defaultValue = "checkstyle.suppressions.file" )
    protected String suppressionsFileExpression;

    /**
     *

     * Specifies the location of the suppressions XML file to use.
     *

     *

     *

     * This parameter is resolved as resource, URL, then file. If successfully
     * resolved, the contents of the suppressions XML is copied into the
     * ${project.build.directory}/checkstyle-supressions.xml file
     * before being passed to Checkstyle for loading.
     *

     *

     *

     * See suppressionsFileExpression for the property that will
     * be made available to your checkstyle configuration.
     *

     *
     * @since 2.0-beta-2
     */
    @Parameter( property = "checkstyle.suppressions.location" )
    protected String suppressionsLocation;

    /**
     * If null, the Checkstyle plugin will display violations on stdout.
     * Otherwise, a text file will be created with the violations.
     */
    @Parameter
    private File useFile;

    /**
     * Specifies the format of the output to be used when writing to the output
     * file. Valid values are "plain" and "xml".
     */
    @Parameter( property = "checkstyle.output.format", defaultValue = "xml" )
    private String outputFileFormat;

    /**
     * Specifies if the Rules summary should be enabled or not.
     */
    @Parameter( property = "checkstyle.enable.rules.summary", defaultValue = "true" )
    private boolean enableRulesSummary;

    /**
     * Specifies if the Severity summary should be enabled or not.
     */
    @Parameter( property = "checkstyle.enable.severity.summary", defaultValue = "true" )
    private boolean enableSeveritySummary;

    /**
     * Specifies if the Files summary should be enabled or not.
     */
    @Parameter( property = "checkstyle.enable.files.summary", defaultValue = "true" )
    private boolean enableFilesSummary;

    /**
     * Specifies if the RSS should be enabled or not.
     */
    @Parameter( property = "checkstyle.enable.rss", defaultValue = "true" )
    private boolean enableRSS;

    /**
     * SiteTool.
     *
     * @since 2.2
     */
    @Component( role = SiteTool.class )
    protected SiteTool siteTool;

    /**
     * The Maven Project Object.
     */
    @Component
    protected MavenProject project;

    /**
     * Link the violation line numbers to the source xref. Will link
     * automatically if Maven JXR plugin is being used.
     *
     * @since 2.1
     */
    @Parameter( property = "linkXRef", defaultValue = "true" )
    private boolean linkXRef;

    /**
     * Location of the Xrefs to link to.
     */
    @Parameter( defaultValue = "${project.reporting.outputDirectory}/xref" )
    private File xrefLocation;

    /**
     * When using custom treeWalkers, specify their names here so the checks
     * inside the treeWalker end up the the rule-summary.
     *
     * @since 2.11
     */
    @Parameter
    private List<String> treeWalkerNames;

    /**
     */
    @Component
    private Renderer siteRenderer;

    /**
     */
    @Component
    protected ResourceManager locator;

    /**
     * CheckstyleRssGenerator.
     *
     * @since 2.4
     */
    @Component( role = CheckstyleRssGenerator.class, hint = "default" )
    protected CheckstyleRssGenerator checkstyleRssGenerator;

    /**
     * @since 2.5
     */
    @Component( role = CheckstyleExecutor.class, hint = "default" )
    protected CheckstyleExecutor checkstyleExecutor;

    protected ByteArrayOutputStream stringOutputStream;

    /** {@inheritDoc} */
    public String getName( Locale locale )
    {
        return getBundle( locale ).getString( "report.checkstyle.name" );
    }

    /** {@inheritDoc} */
    public String getDescription( Locale locale )
    {
        return getBundle( locale ).getString( "report.checkstyle.description" );
    }

    /** {@inheritDoc} */
    protected String getOutputDirectory()
    {
        return outputDirectory.getAbsolutePath();
    }

    /** {@inheritDoc} */
    protected MavenProject getProject()
    {
        return project;
    }

    /** {@inheritDoc} */
    protected Renderer getSiteRenderer()
    {
        return siteRenderer;
    }

    /** {@inheritDoc} */
    public void executeReport( Locale locale )
        throws MavenReportException
    {
        locator.addSearchPath( FileResourceLoader.ID, project.getFile().getParentFile().getAbsolutePath() );
        locator.addSearchPath( "url", "" );

        locator.setOutputDirectory( new File( project.getBuild().getDirectory() ) );

        // for when we start using maven-shared-io and
        // maven-shared-monitor...
        // locator = new Locator( new MojoLogMonitorAdaptor( getLog() ) );

        // locator = new Locator( getLog(), new File(
        // project.getBuild().getDirectory() ) );

        ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();

        try
        {
            CheckstyleExecutorRequest request = createRequest();

            CheckstyleResults results = checkstyleExecutor.executeCheckstyle( request );

            ResourceBundle bundle = getBundle( locale );
            generateReportStatics();
            generateMainReport( results, bundle );
            if ( enableRSS )
            {
                CheckstyleRssGeneratorRequest checkstyleRssGeneratorRequest =
                    new CheckstyleRssGeneratorRequest( this.project, this.getCopyright(), outputDirectory, getLog() );
                checkstyleRssGenerator.generateRSS( results, checkstyleRssGeneratorRequest );
            }

        }
        catch ( CheckstyleException e )
        {
            throw new MavenReportException( "Failed during checkstyle configuration", e );
        }
        catch ( CheckstyleExecutorException e )
        {
            throw new MavenReportException( "Failed during checkstyle execution", e );
        }
        finally
        {
            //be sure to restore original context classloader
            Thread.currentThread().setContextClassLoader( currentClassLoader );
        }
    }

    /**
     * Create the Checkstyle executor request.
     *
     * @return The executor request.
     * @throws MavenReportException If something goes wrong during creation.
     */
    protected abstract CheckstyleExecutorRequest createRequest()
            throws MavenReportException;

    /**
     * Creates and returns the report generation listener.
     *
     * @return The audit listener.
     * @throws MavenReportException If something goes wrong.
     */
    protected AuditListener getListener()
        throws MavenReportException
    {
        AuditListener listener = null;

        if ( StringUtils.isNotEmpty( outputFileFormat ) )
        {
            File resultFile = outputFile;

            OutputStream out = getOutputStream( resultFile );

            if ( "xml".equals( outputFileFormat ) )
            {
                listener = new XMLLogger( out, true );
            }
            else if ( "plain".equals( outputFileFormat ) )
            {
                listener = new DefaultLogger( out, true );
            }
            else
            {
                // TODO: failure if not a report
                throw new MavenReportException( "Invalid output file format: (" + outputFileFormat
                    + "). Must be 'plain' or 'xml'." );
            }
        }

        return listener;
    }

    private OutputStream getOutputStream( File file )
        throws MavenReportException
    {
        File parentFile = file.getAbsoluteFile().getParentFile();

        if ( !parentFile.exists() )
        {
            parentFile.mkdirs();
        }

        FileOutputStream fileOutputStream;
        try
        {
            fileOutputStream = new FileOutputStream( file );
        }
        catch ( FileNotFoundException e )
        {
            throw new MavenReportException( "Unable to create output stream: " + file, e );
        }
        return fileOutputStream;
    }

    /**
     * Creates and returns the console listener.
     *
     * @return The console listener.
     * @throws MavenReportException If something goes wrong.
     */
    protected DefaultLogger getConsoleListener()
        throws MavenReportException
    {
        DefaultLogger consoleListener;

        if ( useFile == null )
        {
            stringOutputStream = new ByteArrayOutputStream();
            consoleListener = new DefaultLogger( stringOutputStream, false );
        }
        else
        {
            OutputStream out = getOutputStream( useFile );

            consoleListener = new DefaultLogger( out, true );
        }

        return consoleListener;
    }

    private void generateReportStatics()
        throws MavenReportException
    {
        ReportResource rresource = new ReportResource( PLUGIN_RESOURCES, outputDirectory );
        try
        {
            rresource.copy( "images/rss.png" );
        }
        catch ( IOException e )
        {
            throw new MavenReportException( "Unable to copy static resources.", e );
        }
    }

    private String getCopyright()
    {
        String copyright;
        int currentYear = Calendar.getInstance().get( Calendar.YEAR );
        if ( StringUtils.isNotEmpty( project.getInceptionYear() )
            && !String.valueOf( currentYear ).equals( project.getInceptionYear() ) )
        {
            copyright = project.getInceptionYear() + " - " + currentYear;
        }
        else
        {
            copyright = String.valueOf( currentYear );
        }

        if ( ( project.getOrganization() != null ) && StringUtils.isNotEmpty( project.getOrganization().getName() ) )
        {
            copyright = copyright + " " + project.getOrganization().getName();
        }
        return copyright;
    }

    private void generateMainReport( CheckstyleResults results, ResourceBundle bundle )
    {
        CheckstyleReportGenerator generator =
            new CheckstyleReportGenerator( getSink(), bundle, project.getBasedir(), siteTool );

        generator.setLog( getLog() );
        generator.setEnableRulesSummary( enableRulesSummary );
        generator.setEnableSeveritySummary( enableSeveritySummary );
        generator.setEnableFilesSummary( enableFilesSummary );
        generator.setEnableRSS( enableRSS );
        generator.setCheckstyleConfig( results.getConfiguration() );
        if ( linkXRef )
        {
            String relativePath = PathTool.getRelativePath( getOutputDirectory(), xrefLocation.getAbsolutePath() );
            if ( StringUtils.isEmpty( relativePath ) )
            {
                relativePath = ".";
            }
            relativePath = relativePath + "/" + xrefLocation.getName();
            if ( xrefLocation.exists() )
            {
                // XRef was already generated by manual execution of a lifecycle
                // binding
                generator.setXrefLocation( relativePath );
            }
            else
            {
                // Not yet generated - check if the report is on its way
                for ( ReportPlugin report : (Iterable<ReportPlugin>) getProject().getReportPlugins() )
                {
                    String artifactId = report.getArtifactId();
                    if ( "maven-jxr-plugin".equals( artifactId ) || "jxr-maven-plugin".equals( artifactId ) )
                    {
                        generator.setXrefLocation( relativePath );
                    }
                }
            }

            if ( generator.getXrefLocation() == null )
            {
                getLog().warn( "Unable to locate Source XRef to link to - DISABLED" );
            }
        }
        if ( treeWalkerNames != null )
        {
            generator.setTreeWalkerNames( treeWalkerNames );
        }
        generator.generateReport( results );
    }

    private static ResourceBundle getBundle( Locale locale )
    {
        return ResourceBundle.getBundle( "checkstyle-report", locale, AbstractCheckstyleReport.class.getClassLoader() );
    }

    /** {@inheritDoc} */
    public void setReportOutputDirectory( File reportOutputDirectory )
    {
        super.setReportOutputDirectory( reportOutputDirectory );
        this.outputDirectory = reportOutputDirectory;
    }
}


text:
angular.module('app').factory('Notification',[function() {
  return {
    _listeners:{},

    /**
    * Adiciona um listener
    * @param name : Nome do evento
    * @param listener : Listener callback
    */
    addEventListener:function(name,listener){
      if(!this._listeners[name]){
          this._listeners[name] = [];
      }
      this._listeners[name].push(listener)
    },

    /**
       * Remove um listener
       * @param name : Nome do evento
       * @param listener : Listener callback
       */
    removeEventListener:function(name,listener){
      if(this._listeners[name]){
        var index = this._listeners[name].indexOf(listener);

        if(index!==-1){
            this._listeners[name].splice(index,1);
        }
      }
    },

    /**
    * Notifica um evento
    * @param Mutiplos parâmetros disponíveis, o primeiro deve ser uma string
    */
    notify:function(){
      var listeners;

      if (typeof arguments[0] !== 'string'){
        console.warn('Notification','Primeiro parâmetro deve ser um nome de evento (String)')
      } else {
        listeners = this._listeners[arguments[0]];

        for(var key in listeners){
          listeners[key].apply(null, arguments);
        }
      }
    },
  };
}])


text:
using System;
using System.Collections.Generic;
using ZyGames.Framework.Cache.Generic;
using ZyGames.Framework.Game.Cache;
using ZyGames.Framework.Game.Service;
using ZyGames.Framework.Collection;
using ZyGames.Framework.Common;
using ZyGames.Tianjiexing.Model;

namespace ZyGames.Tianjiexing.BLL.Action
{

    /// <summary>
    /// 9202_公告列表接口
    /// </summary>
    public class Action9202 : BaseAction
    {
        private int _pageIndex;
        private int _pageSize;
        private int _pageCount;
        private List<GameNotice> _gameNotices;

        public Action9202(ZyGames.Framework.Game.Contract.HttpGet httpGet)
            : base(ActionIDDefine.Cst_Action9202, httpGet)
        {
        }

        public override void BuildPacket()
        {
            PushIntoStack(_pageCount);
            PushIntoStack(_gameNotices.Count);
            foreach (var item in _gameNotices)
            {
                DataStruct dsItem = new DataStruct();
                dsItem.PushIntoStack(item.Title.ToNotNullString());
                dsItem.PushIntoStack(item.Content.ToNotNullString());
                dsItem.PushIntoStack(FormatDate(item.CreateDate));
                dsItem.PushIntoStack(item.NoticeType);
                PushIntoStack(dsItem);
            }
            PushIntoStack(IsToday(_gameNotices) ? 1 : 0);
        }

        public override bool GetUrlElement()
        {
            if (httpGet.GetInt("PageIndex", ref _pageIndex)
                 && httpGet.GetInt("PageSize", ref _pageSize))
            {
                return true;
            }
            return false;
        }

        public override bool TakeAction()
        {
            _gameNotices = new ShareCacheStruct<GameNotice>().FindAll(m => (m.ExpiryDate <= MathUtils.SqlMinDate && m.CreateDate.AddDays(7) >= DateTime.Now) ||
                (m.ExpiryDate > MathUtils.SqlMinDate && (m.ExpiryDate >= DateTime.Now && m.CreateDate.AddDays(7) >= DateTime.Now)));
            //_gameNotices = new ShareCacheStruct<GameNotice>().FindAll(s=>s.ExpiryDate >= DateTime.Now && s.CreateDate.AddDays(7) >= DateTime.Now);
            _gameNotices.QuickSort((x, y) =>
            {
                int result = y.IsTop.CompareTo(x.IsTop);
                if (result == 0)
                {
                    return y.CreateDate.CompareTo(x.CreateDate);
                }
                return result;
            });
            _gameNotices = _gameNotices.GetPaging(_pageIndex, _pageSize, out _pageCount);
            return true;
        }

        private static bool IsToday(List<GameNotice> noticesArray)
        {
            foreach (GameNotice notice in noticesArray)
            {
                if (notice.CreateDate.Date == DateTime.Now)
                {
                    return true;
                }
            }
            return false;
        }
    }
}


text:
package org.apache.beam.runners.spark.translation;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import java.io.Serializable;
import org.apache.beam.sdk.Pipeline;
import org.apache.beam.sdk.coders.CoderRegistry;
import org.apache.beam.sdk.io.FileSystems;
import org.apache.beam.sdk.options.PipelineOptions;
import org.apache.beam.sdk.util.common.ReflectHelpers;

/**
 * The SparkRuntimeContext allows us to define useful features on the client side before our
 * data flow program is launched.
 */
public class SparkRuntimeContext implements Serializable {
  private final String serializedPipelineOptions;
  private transient CoderRegistry coderRegistry;

  SparkRuntimeContext(Pipeline pipeline, PipelineOptions options) {
    this.serializedPipelineOptions = serializePipelineOptions(options);
  }

  /**
   * Use an {@link ObjectMapper} configured with any {@link Module}s in the class path allowing
   * for user specified configuration injection into the ObjectMapper. This supports user custom
   * types on {@link PipelineOptions}.
   */
  private static ObjectMapper createMapper() {
    return new ObjectMapper().registerModules(
        ObjectMapper.findModules(ReflectHelpers.findClassLoader()));
  }

  private String serializePipelineOptions(PipelineOptions pipelineOptions) {
    try {
      return createMapper().writeValueAsString(pipelineOptions);
    } catch (JsonProcessingException e) {
      throw new IllegalStateException("Failed to serialize the pipeline options.", e);
    }
  }

  private static PipelineOptions deserializePipelineOptions(String serializedPipelineOptions) {
    try {
      return createMapper().readValue(serializedPipelineOptions, PipelineOptions.class);
    } catch (IOException e) {
      throw new IllegalStateException("Failed to deserialize the pipeline options.", e);
    }
  }

  public PipelineOptions getPipelineOptions() {
    return PipelineOptionsHolder.getOrInit(serializedPipelineOptions);
  }

  public CoderRegistry getCoderRegistry() {
    if (coderRegistry == null) {
      coderRegistry = CoderRegistry.createDefault();
    }
    return coderRegistry;
  }

  private static class PipelineOptionsHolder {
    // on executors, this should deserialize once.
    private static transient volatile PipelineOptions pipelineOptions = null;

    static PipelineOptions getOrInit(String serializedPipelineOptions) {
      if (pipelineOptions == null) {
        synchronized (PipelineOptionsHolder.class) {
          if (pipelineOptions == null) {
            pipelineOptions = deserializePipelineOptions(serializedPipelineOptions);
          }
        }
        // Register standard FileSystems.
        FileSystems.setDefaultPipelineOptions(pipelineOptions);
      }
      return pipelineOptions;
    }
  }
}


text:
"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _reactRedux = require("react-redux");

var _reselect = require("reselect");

var _playlistSelectors = require("../selectors/playlistSelectors");

var _searchSelectors = require("../selectors/searchSelectors");

var _importSelectors = require("../selectors/importSelectors");

var _LazyOverlay = _interopRequireDefault(require("../components/LazyOverlay"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var mapStateToProps = (0, _reselect.createStructuredSelector)({
  selectedPlaylist: _playlistSelectors.selectedPlaylistSelector,
  showImportPanel: _importSelectors.showImportPanelSelector,
  showSearchResults: _searchSelectors.showSearchResultsSelector
});
var enhance = (0, _reactRedux.connect)(mapStateToProps);
var PlaylistManager = (0, _LazyOverlay.default)({
  loader: function loader() {
    return Promise.resolve().then(() => require('../components/PlaylistManager'));
  },
  title: function title(t) {
    return t('playlists.title');
  }
});

var _default = enhance(PlaylistManager);

exports.default = _default;
//# sourceMappingURL=PlaylistManager.js.map


text:
layout: post
title:  "Assignment 6 Blog Post (The Finale!)"
date:   2016-12-05
categories: jekyll update
---

  Be Presentable

 This Blog Post will be on what I've done for Assignment 6

- Here's a link to our  [Awesome Presentation](https://brynnaw.github.io/newassignment6/#/)

#### **Reflections**

* Team BlueBlueGreen was back at it again! This time Brynna took the reins for
downloading the base repository and making Amanda and I collaborators.
We were able to easily create our slides and decided as a team to not include a lot of words and lists but primarily use pictures.

* We decided to follow Brynna's lead from her community event and do our presentation on `Machine Learning` and `Neural Networks`.

##### *As a team:*
* After we noticed the lovely picture you drew depciting the funnel shape for how to arrange your presentation we decided to split up our research and our slides in 3 different parts

> `Amanda` worked on the introduction and the Overview

> `Erin` I worked on the specifics in the middle and focused my research on `Reinforcement Learning`

> `Brynna` worked on the Applications and some of the Daily Life aspects of Neural Networks

* We did our research individually and created our slide content and then came together to put them together and record our voice-overs for the slides.

*We ran into several challenges that we were able to work together to overcome*

* At one point there was the audio being pulled from the repository that we'd just cloned from, and we had to work several different steps in order to make sure it didn't return.

*And there was a few challenges that I couldn't overcome*

* I tried really hard to upload a video clip from youtube to my presentation, but after several different attempts, I unfortunately wasn't able to find a way to complete this.

> Here's the clip I wanted to include

*Any lightbulbs that came on for you*

* Honestly I think one of my favorite parts of this assignment was the scripting. It seemed to run the smoothest out of the things that we were able to accomplish and I will probably keep finding ways to work on that in the future!

* Also, at one point, I messed up our template and all of our backgrounds and fonts were messed up, but after freaking out `for only a second` I remembered I could revert back to spot where the template wasn't screwed up, and it saved my bacon!

#### Skills and attitudes for this project

* As I mentioned before, I'm enjoying scripting a lot, and `Pandoc` I think has been a team `BlueBlueGreen` favorite, as Amanda's already using it outside of the classroom!

* Also, I enjoy that we can pull things from earlier in the class, like `git revert` and `pandoc`

* This class has also really taught me a lot about teamwork, Obviously I've worked with teams before, but never have I seen such an equal and fair doling out of tasks than with `BlueBlueGreen`

* This assignment was again a lesson in patience for me. I know I might get a little frustrated at times, but I also am able to step back and notice that I'm still learning.

* Each time we complete an assignment I can look back at my work before and see the progress I've made, and while frustrating, I'm extremely proud of how far I've come.

* When I started this class I was completely intimidated and to now be able to look at scripts and work the command line like I know `mostly` what I'm doing, makes me feel like I've grown leaps and bounds from where I was.

#### Using Skills Beyond this class
* I have no doubt I will use these skills after I leave this class

* It is partially due to this class `and the urging of my advisors` that I will be following the Information Science track for the rest of my Graduate School Career!

* Next year I will be taking `Databases I` and I have no doubt that I will be using some of the information that I learned about in this class.

* Also, `Neural Networks` are fascinating!

And now for your enjoyment, I thought I'd leave you with one last laugh!


text:
import React from 'react';
import { Text } from 'native-base';

export const Example = () => {
  return (
    <Text italic>
      <Text bold>Taj Mahal</Text> is in Agra.
    </Text>
  );
};