Skip to content

Instantly share code, notes, and snippets.

View logentries-gists's full-sized avatar

logentries-gists

View GitHub Profile
/**
* sends batch job to a queue for further processing.
*
* @param job
* task that will be serialized and sent to queue
* @return true if job has been successfully queued
*/
public boolean sendJobToWaitQueue(Batch job) {
LOGGER.debug("Trying to push job to queue: " + job.toString());
String jobJson = batchToJson(job);
public class ChannelAdapter {
private static final Logger LOGGER = LoggerFactory.getLogger(ChannelAdapter.class);
private final String waitQueue = "TestSample:waitQueue";
private final String workQueue = "TestSample:workQueue";
private final JedisPool jedisPool;
/**
* ChannelAdapter in charge of communication with messaging
private String getMockResponse(String jsonResource){
String MockResponse = null;
try {
MockResource = Resources.toString(Resources.getResource(jsonResource), Charsets.UTF_8);
}catch(IOException ex){
ex.printStackTrace();
}
return MockResponse;
}
@Test
public void testGetCountOfStudentsWithCourseID() throws IOException {
private String course_id = "CS101";
when(httpClient.jsonGetCourseDetails(eq(course_id))
.thenReturn(getMockResponse("./tests/course/course_details.json"));
Integer count = dao.getCountOfStudents(course_id);
Assert.assertEquals(10, count);
}
private HttpClient httpClient;
@Before
public void setup() {
apiClient = mock(HttpClient.class);
...
...
}
@After
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
import com.google.common.io.Resources;
import com.google.common.base.Charsets;
@Then('^the new current account balance should be "([^"]*)" euros$')
def the_new_current_account_balance_should_be(self, expected_bal):
expected_bal = int(expected_bal)
assert expected_bal >= 0, "Balance cannot be negative"
new_bal = get_balance(account_id)
assert int(new_bal) == expected_bal, "Expected to get %d euros. Instead got %d euros" % (new_bal, expected_bal)
// Given a list of colours
let elements = [{ id:1, name: 'Blue’, value: ‘#0000FF’}, { id:1, name: 'White’, value: ‘#FFFFFF’}, { id:1, name: 'Red', value: ‘#FF0000’}];
// Or a promise for a list of colours
let colourPromise = new ColourService().getAll(); // Assume it returns a promise that resolves an array of colours;
function isPromise(obj) {
… // Check if is a promise
}
function getMap(colours) {
if (isPromise(colours) {
// main.ts
import {jsxFactory} from “jsxFactory”
let div = <div>Hello world from your first component.</div>;
Compiling: tsc –jsx react –reactNamespace jsxFactory –m commons
Results in:
“use strict”;
var jsxFactory_1 = require(“jsxFactory”);
var div = jsxFactory_1. jsxFactory.createElement(“div”, null, “Hello world from your first component.”);
let list = [];
for (let i = 0; i < 5; i++) {
list.push(() => i);
}
list.forEach(f => console.log(f()));
/**** results
>> 0
>> 1
>> 2