Search in sources :

Example 1 with CommandCancelWork

use of org.xel.computation.CommandCancelWork in project elastic-core-maven by OrdinaryDude.

the class CancelWork method processRequest.

@Override
protected JSONStreamAware processRequest(final HttpServletRequest req) throws NxtException {
    final long workId = ParameterParser.getUnsignedLong(req, "work_id", true);
    Work w = Work.getWork(workId);
    if (w == null || w.isClosed())
        return JSONResponses.ERROR_WORK_UNKNOWN;
    CommandCancelWork work = new CommandCancelWork(workId);
    try {
        MessageEncoder.push(work, ParameterParser.getSecretPhrase(req, true));
        return JSONResponses.EVERYTHING_ALRIGHT;
    } catch (IOException e) {
        return JSONResponses.ERROR_INCORRECT_REQUEST;
    }
}
Also used : CommandCancelWork(org.xel.computation.CommandCancelWork) CommandCancelWork(org.xel.computation.CommandCancelWork) Work(org.xel.Work) IOException(java.io.IOException)

Example 2 with CommandCancelWork

use of org.xel.computation.CommandCancelWork in project elastic-core-maven by OrdinaryDude.

the class WorkTest method newWorkTest.

@Test
public void newWorkTest() throws NxtException, IOException {
    redeemPubkeyhash();
    String code = readFile("src/test/testfiles/op2.epl", Charset.forName("UTF-8"));
    String doublecheckcode = new String(code.getBytes());
    System.out.println("[!!]\tcode length: " + code.length());
    CommandNewWork work = new CommandNewWork(100, (short) 15, 1000001, 1000001, 10, 10, code.getBytes());
    MessageEncoder.push(work, AbstractForgingTest.testForgingSecretPhrase);
    // Mine a bit so the work gets confirmed
    AbstractBlockchainTest.forgeNumberOfBlocks(1, AbstractForgingTest.testForgingSecretPhrase);
    // Test work db table
    Assert.assertEquals(1, Work.getCount());
    Assert.assertEquals(1, Work.getActiveCount());
    long id = 0;
    try (DbIterator<Work> wxx = Work.getActiveWork()) {
        Work w = wxx.next();
        id = w.getId();
        System.out.println("Found work in DB with id = " + Long.toUnsignedString(w.getId()));
    }
    CommandCancelWork cancel = new CommandCancelWork(id);
    MessageEncoder.push(cancel, AbstractForgingTest.testForgingSecretPhrase);
    // Mine a bit so the work gets confirmed
    AbstractBlockchainTest.forgeNumberOfBlocks(5, AbstractForgingTest.testForgingSecretPhrase);
    System.out.println("LAST BLOCK:");
    System.out.println(Nxt.getBlockchain().getLastBlock().getJSONObject().toJSONString());
    // Test work db table
    Assert.assertEquals(1, Work.getCount());
    Assert.assertEquals(0, Work.getActiveCount());
    Assert.assertEquals(7, Nxt.getBlockchain().getLastLocallyProcessedHeight());
}
Also used : CommandNewWork(org.xel.computation.CommandNewWork) CommandCancelWork(org.xel.computation.CommandCancelWork) CommandNewWork(org.xel.computation.CommandNewWork) CommandCancelWork(org.xel.computation.CommandCancelWork) Test(org.junit.Test)

Aggregations

CommandCancelWork (org.xel.computation.CommandCancelWork)2 IOException (java.io.IOException)1 Test (org.junit.Test)1 Work (org.xel.Work)1 CommandNewWork (org.xel.computation.CommandNewWork)1