arpadboda commented on a change in pull request #550: MINIFICPP-822 - Nanofi 
raw S2S implementation shouldn't depend on any…
URL: https://github.com/apache/nifi-minifi-cpp/pull/550#discussion_r281181457
 
 

 ##########
 File path: nanofi/tests/CSite2SiteTests.cpp
 ##########
 @@ -60,164 +60,61 @@ TEST_CASE("TestSetPortId", "[S2S1]") {
   free(protocol);
 }
 
-TEST_CASE("TestSetPortIdUppercase", "[S2S2]") {
-  auto stream_ptr = std::unique_ptr<minifi::io::BaseStream>(new 
org::apache::nifi::minifi::io::BaseStream());
-
-  cstream cstrm;
-  cstrm.impl = stream_ptr.get();
-
-  SiteToSiteCPeer peer;
-  initPeer(&peer, &cstrm, "fake_host", 65433, "");
-  CRawSiteToSiteClient * protocol = 
(CRawSiteToSiteClient*)malloc(sizeof(CRawSiteToSiteClient));
-
-  initRawClient(protocol, &peer);
-
-  std::string uuid_str = "C56A4180-65AA-42EC-A945-5FD21DEC0538";
-
-  //setPortId(protocol, uuid_str.c_str());
-
-  //REQUIRE(uuid_str != getPortId(protocol));
-
-  std::transform(uuid_str.begin(), uuid_str.end(), uuid_str.begin(), 
::tolower);
-
-  //REQUIRE(uuid_str == std::string(getPortId(protocol)));
-
-  tearDown(protocol);
-
-  freePeer(&peer);
-
-  free(protocol);
-}
+void sunny_path_bootstrap(minifi::io::BaseStream* stream) {
+  //Verify the magic string
+  char c_array[4];
+  stream->readData((uint8_t*)c_array, 4);
+  REQUIRE(std::string(c_array, 4) == "NiFi");
+  std::array<uint8_t, 5> resp_codes = {0x14, 'R', 'C', 0x1, 0x14};
 
-void sunny_path_bootstrap(SiteToSiteResponder *collector) {
-  char a = 0x14;  // RESOURCE_OK
-  std::string resp_code;
-  resp_code.insert(resp_code.begin(), a);
-  collector->push_response(resp_code);
-
-  // Handshake respond code
-  resp_code = "R";
-  collector->push_response(resp_code);
-  resp_code = "C";
-  collector->push_response(resp_code);
-  char b = 0x1;
-  resp_code = b;
-  collector->push_response(resp_code);
-
-  // Codec Negotiation
-  resp_code = a;
-  collector->push_response(resp_code);
+  for(uint8_t r : resp_codes) {
+    stream->write(&r, 1);
+  }
 }
 
-TEST_CASE("TestSiteToSiteVerifySend", "[S2S3]") {
+void different_version_bootstrap(minifi::io::BaseStream* stream) {
+  uint8_t resp_code = 0x15;
+  stream->write(&resp_code, 1);
 
-  SiteToSiteResponder *collector = new SiteToSiteResponder();
-  sunny_path_bootstrap(collector);
+  uint32_t version = 4;
+  stream->write(version);
 
-  auto stream_ptr = std::unique_ptr<minifi::io::BaseStream>(new 
org::apache::nifi::minifi::io::BaseStream(collector));
+  sunny_path_bootstrap(stream);
+}
 
-  cstream cstrm;
-  cstrm.impl = stream_ptr.get();
+TEST_CASE("TestSiteToBootStrap", "[S2S3]") {
 
-  SiteToSiteCPeer peer;
-  initPeer(&peer, &cstrm, "fake_host", 65433, "");
+  std::array<std::function<void(minifi::io::BaseStream*)>, 2> 
bootstrap_functions = {sunny_path_bootstrap, different_version_bootstrap};
 
-  CRawSiteToSiteClient * protocol = 
(CRawSiteToSiteClient*)malloc(sizeof(CRawSiteToSiteClient));
+  for(const auto& bootstrap_func : bootstrap_functions) {
 
-  initRawClient(protocol, &peer);
+    std::unique_ptr<minifi::io::Socket> socket(new 
minifi::io::RandomServerSocket("localhost"));
+    uint16_t port = socket->getPort();
 
-  std::string uuid_str = "C56A4180-65AA-42EC-A945-5FD21DEC0538";
+    bool c_handshake_ok = false;
 
-  setPortId(protocol, uuid_str.c_str());
+    auto c_client_thread = [&c_handshake_ok, port]() {
+      SiteToSiteCPeer cpeer;
+      initPeer(&cpeer, "localhost", port, "");
 
-  REQUIRE(0 == bootstrap(protocol));
 
 Review comment:
   Some of this could be verified using the socket, although I would prefer 
integration tests to verify transfer. 
   Feel free to argue with this in case you have different opinion. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to