Examples of Reading


Examples of facebook4j.Reading

*/
public class ReadingBuilderTest {

    @Test
    public void testCopy() throws Exception {
        final Reading source = new Reading();
        source.fields("field1", "field2");
        source.filter("testFilter");
        source.limit(100);
        source.locale(Locale.US);
        source.metadata();
        source.offset(1000);
        source.since(new Date());
        source.until(new Date());
        source.withLocation();
       
        Reading copy = ReadingBuilder.copy(source, false);
        assertNotNull("Null copy", copy);
        assertEquals("Copy not equal", source.toString(), copy.toString());

        // skip since and until
        copy = ReadingBuilder.copy(source, true);
        assertNotEquals("Copy equal", source.toString(), copy.toString());
        assertFalse("since", copy.toString().contains("since="));
        assertFalse("until", copy.toString().contains("until="));
    }
View Full Code Here

Examples of facebook4j.Reading

        assertFalse("until", copy.toString().contains("until="));
    }

    @Test
    public void testSetProperties() throws Exception {
        final Reading reading = new Reading();

        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put("fields", "field1,field2");
        properties.put("filter", "testFilter");
        properties.put("limit", "100");
View Full Code Here

Examples of facebook4j.Reading

        // get endpoint properties in a map
        final HashMap<String, Object> properties = new HashMap<String, Object>();
        FacebookPropertiesHelper.getEndpointProperties(endpoint.getConfiguration(), properties);

        // skip since and until fields?
        final Reading reading = (Reading) properties.get(READING_PPROPERTY);
        if (reading != null) {
            final String queryString = reading.toString();
            if (queryString.contains("since=")) {
                // use the user supplied value to start with
                final int startIndex = queryString.indexOf(SINCE_PREFIX) + SINCE_PREFIX.length();
                int endIndex = queryString.indexOf('&', startIndex);
                if (endIndex == -1) {
View Full Code Here

Examples of facebook4j.Reading

        // start by setting the Reading since and until fields,
        // these are used to avoid reading duplicate results across polls
        Map<String, Object> arguments = new HashMap<String, Object>();
        arguments.putAll(endpointProperties);

        Reading reading = (Reading) arguments.remove(READING_PPROPERTY);
        if (reading == null) {
            reading = new Reading();
        } else {
            try {
                reading = ReadingBuilder.copy(reading, true);
            } catch (NoSuchFieldException e) {
                throw new IllegalArgumentException(String.format("Error creating property [%s]: %s",
                    READING_PPROPERTY, e.getMessage()), e);
            } catch (IllegalAccessException e) {
                throw new IllegalArgumentException(String.format("Error creating property [%s]: %s",
                    READING_PPROPERTY, e.getMessage()), e);
            }
        }

        // now set since and until for this poll
        final SimpleDateFormat dateFormat = new SimpleDateFormat(FACEBOOK_DATE_FORMAT);
        final long currentMillis = System.currentTimeMillis();
        if (this.sinceTime == null) {
            // first poll, set this to (current time - initial poll delay)
            final Date startTime = new Date(currentMillis
                - TimeUnit.MILLISECONDS.convert(getInitialDelay(), getTimeUnit()));
            this.sinceTime = dateFormat.format(startTime);
        } else if (this.untilTime != null) {
            // use the last 'until' time
            this.sinceTime = this.untilTime;
        }
        this.untilTime = dateFormat.format(new Date(currentMillis));

        reading.since(this.sinceTime);
        reading.until(this.untilTime);

        arguments.put(READING_PPROPERTY, reading);

        return arguments;
    }
View Full Code Here

Examples of net.sourceforge.stat4j.Reading

    public void testShouldResetWhenLivingLongerThenItsPeriod() throws Exception {

        long timePeriodPlusOne = rate.starttimestamp + rate.period + 1;

        Reading reading = new SettableReading().withTimestamp(timePeriodPlusOne);
        Metric muchYoungerMetric = new Metric("metric", reading);

        // Old period's readings
        Metric oldMetric = new Metric("metric", new Reading());
        rate.applyMetric(oldMetric);
        assertEquals(1, (int) rate.getResult());

        // Force new period by pretending a measure from far future
        rate.applyMetric(muchYoungerMetric);
View Full Code Here

Examples of net.sourceforge.stat4j.Reading

      // Get Calculator
      Calculator calculator =
        (Calculator) calculators.get(statistic.getName());

      // Generate Reading
      Reading reading =
        generateReading(statistic, statistic.getSecond(), log);
      if (reading == null)
        continue;

      if (calculator.isApplyImmediate()) {
View Full Code Here

Examples of net.sourceforge.stat4j.Reading

      // Get Calculator
      Calculator calculator =
        (Calculator) calculators.get(statistic.getName());

      // Generate Reading
      Reading reading =
        generateReading(statistic, statistic.getFirst(), log);
      if (reading == null)
        continue;

      if (calculator.isApplyImmediate()) {
View Full Code Here

Examples of net.sourceforge.stat4j.Reading

        } else {
          // scrape failed
          return null;
        }
      }
      return new Reading(value);
    } else {
      return new Reading();
    }
  }
View Full Code Here

Examples of net.sourceforge.stat4j.Reading

    Reading reading) {
    Map map = null;

    Map cache = getReadingCache(statistic);

    Reading first = (Reading) cache.get(statistic.getName());

    // found match to this reading
    if (first != null) {
      // generate metric
      Metric metric = new Metric(statistic.getName(), first, reading);
View Full Code Here

Examples of net.sourceforge.stat4j.Reading

    }


    public void testShouldAccumulateOccurrences() throws Exception {

        Metric metric = new Metric("metric", new Reading());

        for (int i = 0; i < 5; i++) {
            rate.applyMetric(metric);
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.