int main(int argc, char **argv) { if (argc > 1) factory = argv[1]; // use factory from command line arg by default std::cout << "Connecting to factory " << factory << std::endl; Adder adder; // create unique new remote adder object Counter counter1((char*)"myCounter"); // new counter object "myCounter" (created if not exists) Counter counter2((char*)"myCounter"); // lookup and use counter "myCounter" (this is an alias to counter1!) adder.set(2.0); counter1.set(adder.get()); adder.add(3.0); counter1.inc(); std::cout << "Adder=" << adder.get() << std::endl; std::cout << "Counter=" << counter2.get() << std::endl; // counter2 is an alias for counter1 so this prints the value of counter1 std::cout << "Sleep for 90 seconds to test factory server purging objects:" << std::endl; // counter is periodically incremented which keeps it alive sleep(30); counter1.inc(); std::cout << "Counter=" << counter2.get() << std::endl; sleep(30); counter1.inc(); std::cout << "Counter=" << counter2.get() << std::endl; sleep(30); counter1.inc(); std::cout << "Counter=" << counter2.get() << std::endl; // after 90 secs, the adder should be gone std::cout << "Adder is no longer available:" << std::endl; adder.add(3.0); std::cout << "Adder status = " << adder.status << std::endl; return 0; }
void ArchiveWriter::add_base_objects(const std::vector<FileSystemObject *> &base_objects){ zekvok_assert(this->state == State::FilesWritten); this->state = State::FsosWritten; this->entries_size_in_archive = 0; boost::iostreams::stream<ByteCounterOutputFilter> counter(*this->nested_stream, &this->entries_size_in_archive); std::ostream *stream = &counter; std::shared_ptr<std::ostream> crypto; if (this->keypair){ crypto = CryptoOutputFilter::create(default_crypto_algorithm, *stream, &keys->get_key(this->archive_key_index), &keys->get_iv(this->archive_key_index)); this->archive_key_index++; stream = crypto.get(); } bool mt = true; boost::iostreams::stream<LzmaOutputFilter> lzma(*stream, &mt, 8); for (auto i : base_objects){ std::uint64_t bytes_processed = 0; { boost::iostreams::stream<ByteCounterOutputFilter> counter2(lzma, &bytes_processed); SerializerStream ss(counter2); ss.begin_serialization(*i, config::include_typehashes); } this->base_object_entry_sizes.push_back(bytes_processed); } }
int main() { Counter counter1 ; //uses the default constructor std::cout << counter1 << std::endl; counter1.increaseBy(3); std::cout << counter1 << std::endl; Counter counter2(3); if(counter1==counter2) std::cout << "They are equal!" << std::endl; return 0; }
//checks that the reduce function is correctly adding the results of two tasks TEST(MpiWordCounterTests, CheckReduceIsSummingCorrectly) { //four fours and three threes std::vector<std::string> example = { "four", "four", "three", "four", "three", "three", "four" }; mpi_word_counter counter1("four", example); mpi_word_counter counter2("three", example); counter1.map(0, example.size()-1); counter2.map(0, example.size()-1); counter1.reduce(counter2.get_count()); ASSERT_EQ(7, counter1.get_count()); //4+3 }
int main(){ int i; char* s = "Counter = "; for (i = 0; i < 5; i++){ if (i % 2){ printf("Iteração %d\n",i); counter1(); }else{ printf("Iteração %d\n",i); counter2(); } } }
TEST(time, timer_create_multiple) { Counter counter1(Counter::CountNotifyFunction); Counter counter2(Counter::CountNotifyFunction); Counter counter3(Counter::CountNotifyFunction); ASSERT_EQ(0, counter1.Value()); ASSERT_EQ(0, counter2.Value()); ASSERT_EQ(0, counter3.Value()); counter2.SetTime(0, 500000000, 0, 0); sleep(1); EXPECT_EQ(0, counter1.Value()); EXPECT_EQ(1, counter2.Value()); EXPECT_EQ(0, counter3.Value()); }
TEST(time, timer_create_multiple) { Counter counter1(Counter::CountNotifyFunction); counter1.Create(); Counter counter2(Counter::CountNotifyFunction); counter2.Create(); Counter counter3(Counter::CountNotifyFunction); counter3.Create(); ASSERT_EQ(0, counter1.value); ASSERT_EQ(0, counter2.value); ASSERT_EQ(0, counter3.value); SetTime(counter2.timer_id, 0, 1, 0, 0); usleep(500000); EXPECT_EQ(0, counter1.value); EXPECT_EQ(1, counter2.value); EXPECT_EQ(0, counter3.value); }
void PerfResourceCounterTest::testNegative() { NoPayloadCounter::Container container; NoPayloadCounter counter(&container); NoPayloadCounter counter2(&container); for (quint64 i = 0; i < 100; i += 10) { counter.request(10); counter.obtain(i + 1); counter2.request(10); counter2.obtain(100 + i + 1); } for (quint64 i = 0; i < 100; i += 10) { counter.release(i + 1); counter.release(100 + i + 1); } QCOMPARE(counter.maxTotal(), 100ll); QCOMPARE(counter.minTotal(), -100ll); }
void PerfResourceCounterTest::testMultiCounter() { NoPayloadCounter::Container container; NoPayloadCounter counter1(&container); NoPayloadCounter counter2(&container); QCOMPARE(counter1.currentTotal(), 0ll); QCOMPARE(counter2.currentTotal(), 0ll); for (quint64 i = 0; i < 100; i += 10) { counter1.request(10); counter1.obtain(i + 1); } QCOMPARE(counter1.currentTotal(), 100ll); QCOMPARE(counter2.currentTotal(), 0ll); for (quint64 i = 100; i < 200; i += 10) { counter2.request(10); counter2.obtain(i + 1); } QCOMPARE(counter1.currentTotal(), 100ll); QCOMPARE(counter2.currentTotal(), 100ll); for (quint64 i = 0; i < 100; i += 10) counter2.release(i + 1); QCOMPARE(counter1.currentTotal(), 100ll); QCOMPARE(counter2.currentTotal(), 0ll); for (quint64 i = 100; i < 200; i += 10) counter1.release(i + 1); QCOMPARE(counter1.currentTotal(), 0ll); QCOMPARE(counter2.currentTotal(), 0ll); }